Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CamMovement : MonoBehaviour
- {
- public GameObject Parent;
- //Checks if the camera collides with something
- void OnTriggerStay(Collider other)
- {
- //When colliding, the camera moves up and back from the player object
- transform.position += new Vector3(0, 0.2f, -0.2f);
- }
- void Update()
- {
- //makes sure the camera always looks at the player object
- transform.LookAt(Parent.transform);
- //Moves the camera back to the normal (local) position
- if (transform.localPosition.y > 4.5f)
- {
- transform.position += new Vector3(0, Time.deltaTime * -4f, Time.deltaTime * 4f);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement