1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using UnityEngine;
- using System.Collections;
- public class CompleteCameraController : MonoBehaviour
- {
- public bool Loop;
-
- Vector3 playerPrevPos, playerMoveDir;
-
- public Vector3 offset;
- public Transform Target;
- public float distance = 2.8f;
- public float targetHeight = 2.0f;
- private float x = 0.0f;
- private float y = 0.0f;
- void Start()
- {
- var angles = transform.eulerAngles;
- x = angles.x;
- y = angles.y;
- }
- public void ResetCameraOnStartLeve()
- {
- distance = 8;
- targetHeight = 2;
- }
- void LateUpdate()
- {
- if (!Target)
- return;
- y = Target.eulerAngles.y;
- // ROTATE CAMERA:
- Quaternion rotation = Quaternion.Euler(x, y, 0);
- transform.rotation = rotation;
- // POSITION CAMERA:
- var position = Target.position - (rotation * Vector3.forward * distance + new Vector3(0, -targetHeight, 0));
- transform.position = position;
- }
- //// Use this for initialization
- //void Start()
- //{
- // offset = transform.position - player.transform.position;
- // distance = offset.magnitude;
- // playerPrevPos = player.transform.position;
- //}
- //void LateUpdate()
- //{
- // playerMoveDir = player.transform.position - playerPrevPos;
- // if (playerMoveDir != Vector3.zero)
- // {
- // playerMoveDir.Normalize();
- // transform.position = player.transform.position - playerMoveDir * distance;
- // transform.position = new Vector3(transform.position.x, transform.position.y + 5f, transform.position.z); // required height
- // transform.LookAt(Vector3.Lerp(transform.position,player.transform.position, Time.deltaTime * 5));
- // playerPrevPos = player.transform.position;
- // }
- //}
- }
|