Пример #1
0
    void FixedUpdate()
    {
        if (Input.GetKeyDown(KeyCode.L))
        {
            Debug.Log("X: " + rigidBody.position.x + ", Y: " + rigidBody.position.y);
        }

        if (Input.GetKey(KeyCode.UpArrow))
        {
            if (audioSource.clip != accelerating)
            {
                audioSource.clip = accelerating;
                audioSource.Play();
            }
            physics.Accelerate();
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            if (audioSource.clip != accelerating)
            {
                audioSource.clip = accelerating;
                audioSource.Play();
            }
            physics.Reverse();
        }
        if (!Input.GetKey(KeyCode.DownArrow) && !Input.GetKey(KeyCode.UpArrow))
        {
            if (audioSource.clip != idle)
            {
                audioSource.clip = idle;
                audioSource.Play();
            }
            physics.ResetForce();
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            physics.SteeringWheelPos = 5.0f;
        }
        else if (Input.GetKey(KeyCode.RightArrow))
        {
            physics.SteeringWheelPos = -5.0f;
        }
        else
        {
            physics.SteeringWheelPos = 0;
        }
    }
Пример #2
0
    private void Update()
    {
        if (!checkpointManager.isAtLastCheckpoint && checkpointManager.isNearNextCheckpoint)
        {
            checkpointManager.Update();
            if (checkpointManager.isAtLastCheckpoint)
            {
                gameController.OnFinishLineEnter("player");
            }
        }

        if (carAI.action == Action.Forward || carAI.action == Action.ForwardLeft || carAI.action == Action.ForwardRight)
        {
            physics.Accelerate();
        }
        if (carAI.action == Action.Reverse)
        {
            physics.Reverse();
        }
        if (carAI.action == Action.Forward || carAI.action != Action.Forward || carAI.action != Action.None)
        {
            physics.ResetForce();
        }
        if (carAI.action == Action.Left || carAI.action == Action.ForwardLeft)
        {
            physics.SteeringWheelPos = 5.0f;
        }
        else if (carAI.action == Action.Right || carAI.action == Action.ForwardRight)
        {
            physics.SteeringWheelPos = -5.0f;
        }
        else
        {
            physics.SteeringWheelPos = 0;
        }
    }