Beispiel #1
0
    private void FixedUpdate()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            SceneManager.LoadScene("Menu");
        }
        if (hp <= 0 && !died)
        {
            cooldown -= Time.deltaTime;
            if (doOnce)
            {
                doOnceWhenDead();
            }
            _rigidbody.velocity = new Vector3(0, 0, 0); //make hin no move

            if (cooldown <= 0)
            {
                respawnAfterCooldown();
            }
        }

        dir   = Vector3.zero;
        dir.x = Input.GetAxis("LeftVertical" + id);
        dir.z = Input.GetAxis("LeftHorizontal" + id);

        var rotationX = Input.GetAxis("RightHorizontal" + id);
        var rotationY = -Input.GetAxis("RightVertical" + id);


        if (id == 0)
        {
            if (Input.GetKey(KeyCode.W))
            {
                dir.x = -1;
            }
            if (Input.GetKey(KeyCode.S))
            {
                dir.x = 1;
            }
            if (Input.GetKey(KeyCode.A))
            {
                dir.z = -1;
            }
            if (Input.GetKey(KeyCode.D))
            {
                dir.z = 1;
            }
            if (Input.GetKey(KeyCode.C))
            {
                transform.Rotate(Vector3.up, -ang);
            }
            if (Input.GetKey(KeyCode.B))
            {
                transform.Rotate(Vector3.up, ang);
            }
            if (Input.GetKey(KeyCode.V))
            {
                if (weapon)
                {
                    weapon.Fire();
                }
            }
        }
        else if (id == 1)
        {
            if (Input.GetKey(KeyCode.I))
            {
                dir.x = -1;
            }
            if (Input.GetKey(KeyCode.K))
            {
                dir.x = 1;
            }
            if (Input.GetKey(KeyCode.J))
            {
                dir.z = -1;
            }
            if (Input.GetKey(KeyCode.L))
            {
                dir.z = 1;
            }
            if (Input.GetKey(KeyCode.Comma))
            {
                transform.Rotate(Vector3.up, -ang);
            }
            if (Input.GetKey(KeyCode.Slash))
            {
                transform.Rotate(Vector3.up, ang);
            }
            if (Input.GetKey(KeyCode.Period))
            {
                if (weapon)
                {
                    weapon.Fire();
                }
            }
        }

        if (dir.x < 0 || dir.x > 0 || dir.z < 0 || dir.z > 0)
        {
            var look = new Vector3(dir.x, 0, dir.z);
            model.transform.rotation = Quaternion.Slerp(model.transform.rotation, Quaternion.LookRotation(look), 0.3f);
        }

        if (hp > 0)
        {
            if (onIce)
            {
                _rigidbody.AddForce(dir.normalized * vel);
            }
            else
            {
                _rigidbody.velocity = dir.normalized * vel;
            }
        }

        if (Math.Abs(_rigidbody.velocity.magnitude) > 0.1)
        {
            anim.SetBool("running", true);
        }
        else
        {
            anim.SetBool("running", false);
        }


        if (hp > 0)
        {
            if (rotationX < 0 || rotationX > 0 || rotationY < 0 || rotationY > 0)
            {
                var look = new Vector3(rotationX, 0, rotationY);
                transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(look), 0.3f);
            }
            else
            {
                _rigidbody.angularVelocity = Vector3.zero;
            }
        }
        #if UNITY_STANDALONE_WIN
        if (Input.GetAxis("FireW" + id) > 0.5)
        {
            if (weapon)
            {
                weapon.Fire();
            }
        }
        #endif

        #if UNITY_STANDALONE_LINUX
        if (Math.Abs(Input.GetAxis("FireL" + id)) > 0.5)
        {
            if (weapon)
            {
                weapon.Fire();
            }
        }
        #endif


        if (Input.GetButton("Back" + id))
        {
        }
    }