// Update is called once per frame
 void Update()
 {
     transform.position += transform.up * speed * Time.deltaTime;
     if (!countdownScript.ContainsCountdown("lifeSpan") || GameController.instance.gameState == 3)
     {
         Destroy(gameObject);
     }
 }
Exemple #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        invulnerableShield.SetActive(invulnerable); //show that ship is invulnerable for other players, too

        if (GameController.instance.gameState == 3)
        {
            transform.rotation   = Quaternion.identity;
            rb2d.velocity        = Vector3.zero;
            rb2d.angularVelocity = 0f;
            return;
        }

        if (!isLocalPlayer)
        {
            return;
        }

        if (SceneManager.GetActiveScene().name == "Lobby")
        {
            return;
        }

        if (lives <= 0)
        {
            return;
        }

        if (!spawnedInPos)
        {
            Spawn();
            spawnedInPos = true;
        }

        if (invulnerable && !countdownScript.ContainsCountdown("Invulnerable"))
        {
            invulnerable = false;
            GetComponent <Player_SyncLives>().TransmitInvulnerability(false);
        }
        else if (countdownScript.ContainsCountdown("Invulnerable") && !invulnerable)
        {
            invulnerable = true;
            GetComponent <Player_SyncLives>().TransmitInvulnerability(true);
        }

        if (loseLifeDelay > 0)
        {
            loseLifeDelay -= Time.deltaTime;
        }

        //check speed
        if (rb2d.velocity.magnitude > maxSpeed)
        {
            rb2d.AddForce(-rb2d.velocity * (rb2d.velocity.magnitude - maxSpeed));
        }
        //check speed end

        action = "Neutral";
        if (Input.GetKey(KeyCode.W))
        {
            action = "GoForward";
            if (Mathf.Abs(rb2d.velocity.magnitude) < maxSpeed)
            {
                rb2d.AddForce(transform.up * speed);
            }
        }
        if (Input.GetKey(KeyCode.S))
        {
            action = "GoBackward";
            if (Mathf.Abs(rb2d.velocity.magnitude) < maxSpeed)
            {
                rb2d.AddForce(-transform.up * speed);
            }
        }
        if (Input.GetKey(KeyCode.A))
        {
            transform.Rotate(Vector3.forward * 3);
        }
        if (Input.GetKey(KeyCode.D))
        {
            transform.Rotate(Vector3.back * 3);
        }
        UpdateAnimator(action);

        if (Input.GetKey(KeyCode.Space))
        {
            if (Time.time > nextFire && !countdownScript.ContainsCountdown("Invulnerable"))
            {
                CmdFireBullet();
                nextFire = Time.time + fireRate;
            }
        }
    }