Пример #1
0
    private void readInput()
    {
        //Movement
        rb.velocity        = Vector3.zero;
        rb.angularVelocity = Vector3.zero;
        /* Joystick Inputs */
        if (Input.GetAxis("Horizontal Stick") != 0)
        {
            transform.localPosition += new Vector3(Input.GetAxis("Horizontal Stick") * Time.deltaTime * getTimeScale() * moveSpeed, 0, 0);
        }

        if (Input.GetAxis("Vertical Stick") != 0)
        {
            transform.localPosition += new Vector3(0, 0, Input.GetAxis("Vertical Stick") * Time.deltaTime * getTimeScale() * moveSpeed);
        }

        if (Input.GetButtonDown("Melee"))
        {
            scytheAttack.Attack();
        }

        /* Rotation */
        float rsh = Input.GetAxis("Right Horizontal Stick");
        float rsv = Input.GetAxis("Right Vertical Stick");

        //Don't always reset the angle to 0 if the stick goes dead - wait for the player to move the angle themselves.
        if (rsh != 0 || rsv != 0)
        {
            //Rotate around the y-axis
            transform.eulerAngles = new Vector3(transform.eulerAngles.x, Mathf.Atan2(rsh, rsv) * Mathf.Rad2Deg, transform.eulerAngles.z);

            //Fire each of the weapons in the direction the player is pointing
            foreach (Weapon wep in gameObject.GetComponentsInChildren <Weapon>())
            {
                wep.FireBullet();
            }
        }

        /* Key Inputs */
        if (Input.GetButton("Horizontal Key"))
        {
            transform.localPosition += new Vector3(Input.GetAxis("Horizontal Key") * Time.deltaTime * getTimeScale() * moveSpeed, 0, 0);
        }

        if (Input.GetButton("Vertical Key"))
        {
            transform.localPosition += new Vector3(0, 0, Input.GetAxis("Vertical Key") * Time.deltaTime * getTimeScale() * moveSpeed);
        }

        if (Input.GetButtonDown("Slow Time"))
        {
            timeScale.slowTime();
        }
        else if (Input.GetButtonDown("Accelerate Time"))
        {
            timeScale.accelerateTime();
        }
    }