Пример #1
0
 void ProcessInput()
 {
     if (Input.GetKeyDown(KeyCode.W))
     {
         _command     = Control.Commands.UP;
         _rndr.sprite = upCursor;
     }
     if (Input.GetKeyDown(KeyCode.S))
     {
         _command     = Control.Commands.DOWN;
         _rndr.sprite = downCursor;
     }
     if (Input.GetKeyDown(KeyCode.A))
     {
         _command     = Control.Commands.BACK;
         _rndr.sprite = backCursor;
     }
     if (Input.GetKeyDown(KeyCode.D))
     {
         _command     = Control.Commands.FORWARD;
         _rndr.sprite = forwardCursor;
     }
     if (Input.GetKeyDown(KeyCode.Space))
     {
         _command     = Control.Commands.FIRE;
         _rndr.sprite = fireCursor;
     }
 }
Пример #2
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "enemy_bullet")
        {
            if (_canBeHit)
            {
                Damage();
                Destroy(other.gameObject);
            }
        }

        if (other.tag == "ammo")
        {
            bullets += 2;
            Destroy(other.gameObject);
        }

        if (other.tag == "control")
        {
            Control.Commands cmd    = other.GetComponent <Control>().command;
            Vector3          target = transform.position;

            float bTop    = 0.7f;
            float bBottom = -1.7f;
            float bLeft   = -4.7f;
            float bRight  = 4.7f;

            switch (cmd)
            {
            case Control.Commands.UP:
                target += Vector3.up;
                if (target.y < bTop)
                {
                    StartCoroutine(Move(target));
                }
                break;

            case Control.Commands.DOWN:
                target += Vector3.down;
                if (target.y > bBottom)
                {
                    StartCoroutine(Move(target));
                }
                break;

            case Control.Commands.FORWARD:
                target += Vector3.right;
                if (target.x < bRight)
                {
                    StartCoroutine(Move(target));
                }
                break;

            case Control.Commands.BACK:
                target += Vector3.left;
                if (target.x > bLeft)
                {
                    StartCoroutine(Move(target));
                }
                break;

            case Control.Commands.FIRE:
                Fire();
                break;
            }
            Destroy(other.gameObject);
        }
    }
Пример #3
0
 void Init()
 {
     _command     = Control.Commands.FORWARD;
     _rndr.sprite = forwardCursor;
 }