Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (!isLocalPlayer)
        {
            return;
        }

        if (myShoot == null)
        {
            myShoot = this.GetComponent <shoot>();
            if (myShoot == null)
            {
                Debug.Log("myShoot in controlls is null!");
                return;
            }
        }
        if (myMovement == null)
        {
            myMovement = this.GetComponent <movement>();
            if (myMovement == null)
            {
                Debug.Log("myMovement in controlls is null!");
                return;
            }
        }

        if (Input.GetAxis("Horizontal") > 0)
        {
            myMovement.right();
        }
        else if (Input.GetAxis("Horizontal") < 0)
        {
            myMovement.left();
        }

        if (Input.GetAxis("Vertical") > 0)
        {
            myMovement.forward();
        }
        else if (Input.GetAxis("Vertical") < 0)
        {
            myMovement.backward();
        }

        if (Input.GetButtonDown("Fire1"))
        {
            //Debug.Log("Peng Peng");
            myShoot.CmdFire();
        }
    }
Beispiel #2
0
    public void turnTowards(Vector3 v3)
    {
        Vector3 deltaPosition  = v3 - transform.position; //new Vector2(v3.x - transform.position.x, v3.z - transform.position.z);
        float   targetRotation = Vector2.SignedAngle(new Vector2(transform.forward.x, transform.forward.z), new Vector2(deltaPosition.x, deltaPosition.z));

        //Debug.Log("trying to turn towards: " + v3.ToString() + " , deltaPosition: " + deltaPosition + " , targetRotation: " + targetRotation);

        if (targetRotation < 0)
        {
            myMovement.right();
        }
        else if (targetRotation > 0)
        {
            myMovement.left();
        }
    }