You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.2 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. public class script : MonoBehaviour {
  4. public GameObject player;
  5. private thirdPersonController playerController;
  6. public float minDistance;
  7. private float maxDistance;
  8. private bool colliding = false;
  9. private float curCameraX;
  10. private float curCameraY;
  11. private Vector3 curPosition;
  12. // Use this for initialization
  13. void Start () {
  14. playerController = player.GetComponent<thirdPersonController> ();
  15. maxDistance = playerController.cameraDistance;
  16. }
  17. // Update is called once per frame
  18. void Update () {
  19. if (!colliding && playerController.cameraDistance < maxDistance && (curCameraX != playerController.cameraX ||curCameraY != playerController.cameraY || player.transform.position != curPosition))
  20. playerController.cameraDistance += 0.2f;
  21. }
  22. void OnTriggerStay(Collider other) {
  23. colliding = true;
  24. Debug.Log ("cameraCollider");
  25. if (playerController.cameraDistance > minDistance) {
  26. playerController.cameraDistance -= 0.2f;
  27. curCameraX = playerController.cameraX;
  28. curCameraY = playerController.cameraY;
  29. curPosition = player.transform.position;
  30. }
  31. }
  32. void OnTriggerExit(Collider other) {
  33. colliding = false;
  34. }
  35. }