Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class PlayerController : MonoBehaviour
- {
- [SerializeField] float speed = 15.0f;
- [SerializeField] float turnSpeed = 35.0f;
- private float horizontalInput;
- private float forwardInput;
- //camera switch
- public Camera mainCamera;
- public Camera hoodCamera;
- public KeyCode switchKey;
- //2 player
- public string inputID;
- void FixedUpdate()
- {
- //player input
- //control left/right movement
- horizontalInput = Input.GetAxis("Horizontal" + inputID);
- //control forward and back movement
- forwardInput = Input.GetAxis("Vertical" + inputID);
- //Move the vehicle forward
- transform.Translate(Vector3.forward * Time.deltaTime * speed * forwardInput);
- //have vehicle rotate as it turns
- transform.Rotate(Vector3.up * Time.deltaTime * turnSpeed * horizontalInput);
- if (Input.GetKeyDown(switchKey))
- {
- mainCamera.enabled = !mainCamera.enabled;
- hoodCamera.enabled = !hoodCamera.enabled;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement