Exemple #1
0
    void FixedUpdate()
    {
        float horiz = Input.GetAxis("Horizontal");
        float verti = Input.GetAxis("Vertical");

        float rotation = 0;

        if (Input.GetKey(KeyCode.J))
        {
            rotation = 1;
        }
        else if (Input.GetKey(KeyCode.K))
        {
            rotation = -1;
        }

        Vector3 direc = new Vector3(verti, -horiz, rotation);

        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            boost = true;

            if (verti > 0)
            {
                mainRocket.fire();
            }
            else
            {
                mainRocket.stop();
            }
        }
        else
        {
            boost = false;
            mainRocket.stop();
        }

        foreach (ParticleSystem thruster in rcs)
        {
            Thruster rc = thruster.GetComponent <Thruster>();

            float n       = Vector3.Dot(rc.direction, direc);
            bool  rotOver = (rotation > 0 && rc.direction.z > 0) || (rotation < 0 && rc.direction.z < 0);

            if ((n > 0.5 || rotOver) && !(boost && rc.direction.x > 0))
            {
                rc.fire();
            }
        }
    }