Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5.  
  6.  
  7. public class CamMovement : MonoBehaviour
  8. {
  9. public GameObject Parent;
  10.  
  11. //Checks if the camera collides with something
  12. void OnTriggerStay(Collider other)
  13. {
  14. //When colliding, the camera moves up and back from the player object
  15. transform.position += new Vector3(0, 0.2f, -0.2f);
  16. }
  17.  
  18.  
  19. void Update()
  20. {
  21. //makes sure the camera always looks at the player object
  22. transform.LookAt(Parent.transform);
  23.  
  24. //Moves the camera back to the normal (local) position
  25. if (transform.localPosition.y > 4.5f)
  26. {
  27. transform.position += new Vector3(0, Time.deltaTime * -4f, Time.deltaTime * 4f);
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement