Guest User

Untitled

a guest
Feb 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class CameraMovement : MonoBehaviour
  6. {
  7.  
  8. public GameObject player; //Public variable to store a reference to the player game object
  9.  
  10.  
  11. private Vector3 offset; //Private variable to store the offset distance between the player and camera
  12.  
  13. // Use this for initialization
  14. void Start()
  15. {
  16. //Calculate and store the offset value by getting the distance between the player's position and camera's position.
  17. offset = transform.position - player.transform.position;
  18. }
  19.  
  20. // LateUpdate is called after Update each frame
  21. void LateUpdate()
  22. {
  23. // Set the position of the camera's transform to be the same as the player's, but offset by the calculated offset distance.
  24. transform.position = player.transform.position + offset;
  25. }
  26. }
Add Comment
Please, Sign In to add comment