Exemplo n.º 1
0
    public override void ControlTank()
    {
        switch (_move)
        {
        case 1:
            MoveDirection = new Vector2(0, 1);
            Rotation      = new Vector3(0, 0, 0);
            break;

        case 2:
            MoveDirection = new Vector2(0, -1);
            Rotation      = new Vector3(0, 0, 180);
            break;

        case 3:
            MoveDirection = new Vector2(-1, 0);
            Rotation      = new Vector3(0, 0, 90);
            break;

        case 4:
            MoveDirection = new Vector2(1, 0);
            Rotation      = new Vector3(0, 0, -90);
            break;

        default:
            MoveDirection = new Vector2(0, 0);
            break;
        }
        _changeMove = false;
        if (Fire)
        {
            Fire = false;
            Rigidbody2D _bulletInstance = Instantiate(BulletRb, GunTransform.position, Quaternion.identity) as Rigidbody2D;
            _bulletInstance.velocity = GunTransform.TransformDirection(Vector2.up * BulletSpeed);
            Bullet _bullet = BulletRb.transform.GetComponent <Bullet>();
            _bullet._isEnemy = 2;
        }
        TankTransform.localRotation = Quaternion.Euler(Rotation);
        if (HpTank <= 0)
        {
            Destroy(gameObject);
            GameControl.score += 1;
        }
    }
Exemplo n.º 2
0
 public override void ControlTank()
 {
     if (Input.GetKey(KeyCode.W))
     {
         MoveDirection = new Vector2(0, 1);
         Rotation = new Vector3(0, 0, 0);
     }
     else if (Input.GetKey(KeyCode.S))
     {
         MoveDirection = new Vector2(0, -1);
         Rotation = new Vector3(0, 0, 180);
     }
     else if (Input.GetKey(KeyCode.A))
     {
         MoveDirection = new Vector2(-1, 0);
         Rotation = new Vector3(0, 0, 90);
     }
     else if (Input.GetKey(KeyCode.D))
     {
         MoveDirection = new Vector2(1, 0);
         Rotation = new Vector3(0, 0, -90);
     }
     else
     {
         MoveDirection = new Vector2(0, 0);
     }
     if (Input.GetMouseButtonDown(0))
     {
         if (Fire)
         {
             Fire = false;
             Rigidbody2D _bulletInstance = Instantiate(BulletRb, GunTransform.position, Quaternion.identity) as Rigidbody2D;
             _bulletInstance.velocity = GunTransform.TransformDirection(Vector2.up * BulletSpeed);
             _bulletInstance.GetComponent<Bullet>()._isEnemy = 1;
         }
     }
     TankTransform.localRotation = Quaternion.Euler(Rotation);
     if (HpTank <= 0)
     {
         Destroy(gameObject);
         GameControl.playerDead = true;
     }
 }