Advertisement
femoreti

Untitled

Feb 19th, 2020
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. public class PlayerController : MonoBehaviour
  2. {
  3.     public static PlayerController instance;
  4.  
  5.     private Rigidbody rb;
  6.     public float _speed = 1;
  7.     private float _playerSpeed;
  8.  
  9.     // Start is called before the first frame update
  10.     void Awake()
  11.     {
  12.         instance = this;
  13.  
  14.         rb = GetComponent<Rigidbody>();
  15.     }
  16.  
  17.     private void Update()
  18.     {
  19.  
  20.     }
  21.  
  22.     // Update is called once per frame
  23.     void FixedUpdate()
  24.     {
  25.         _playerSpeed = Mathf.Lerp(_playerSpeed, _speed, Time.deltaTime);
  26.  
  27.         rb.velocity = new Vector3(rb.velocity.x, rb.velocity.y, (_playerSpeed * 100 * Time.fixedDeltaTime));
  28.  
  29.         if (transform.position.z - Camera.main.transform.position.z >= 15f) //Move camera to follow player
  30.         {
  31.             Camera.main.transform.position = new Vector3(0, Camera.main.transform.position.y, transform.position.z - 15f);
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement