Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (transform.position.x == destination.x && transform.position.y == destination.y)
        {
            if (bMoving)
            {
                bMoving = false;
                whenUnitFirstArriveDestination();
            }
        }
        else
        {
            bMoving = true;
        }


        Vector2 dir      = new Vector2(destination.x - transform.position.x, destination.y - transform.position.y);
        Vector2 velocity = dir.normalized * speed * Time.deltaTime;

        velocity = Vector2.ClampMagnitude(velocity, dir.magnitude);

        transform.Translate(velocity);

        gameObject.GetComponent <SpriteRenderer>().sprite = UIManager.Instance.unitSprites[spriteIndex];

        thisUnitHasBeenClicked = false;

        if (m_pSoldier != null && m_pSoldier.getCurrentHP() <= 0)
        {
            int money = m_pSoldier.getMoneyByKillingEnemy();
            int xp    = m_pSoldier.getXPByKillingEnemy();
            if (unitAlign == 0)
            {
                m_player2.setMoney(money + m_player2.getMoney());
                m_player2.setXP(xp + m_player2.getXP());
            }
            else if (unitAlign == 1)
            {
                m_player1.setMoney(money + m_player1.getMoney());
                m_player1.setXP(xp + m_player1.getXP());
            }
            GameManager.Instance.modifyUnitDic(unitAlign, gameObject.name);
            Destroy(gameObject);
        }
    }