using UnityEngine; using System.Collections; public class script : MonoBehaviour { public GameObject player; private thirdPersonController playerController; public float minDistance; private float maxDistance; private bool colliding = false; private float curCameraX; private float curCameraY; private Vector3 curPosition; // Use this for initialization void Start () { playerController = player.GetComponent (); maxDistance = playerController.cameraDistance; } // Update is called once per frame void Update () { if (!colliding && playerController.cameraDistance < maxDistance && (curCameraX != playerController.cameraX ||curCameraY != playerController.cameraY || player.transform.position != curPosition)) playerController.cameraDistance += 0.2f; } void OnTriggerStay(Collider other) { colliding = true; Debug.Log ("cameraCollider"); if (playerController.cameraDistance > minDistance) { playerController.cameraDistance -= 0.2f; curCameraX = playerController.cameraX; curCameraY = playerController.cameraY; curPosition = player.transform.position; } } void OnTriggerExit(Collider other) { colliding = false; } }