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.

33 lines
703 B

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class DynamicCamera : MonoBehaviour
  5. {
  6. public GameObject target;
  7. public float camHeight;
  8. public Vector2 Clamp;
  9. void Start()
  10. {
  11. }
  12. void Follow()
  13. {
  14. Vector3 tempDest = target.transform.position;
  15. camHeight = Mathf.Clamp(target.transform.localScale.magnitude,Clamp.x,Clamp.y);
  16. tempDest -= transform.forward * camHeight;
  17. Vector3 destination = Vector3.Lerp(transform.position, tempDest, 10f * Time.deltaTime);
  18. transform.position = destination;
  19. }
  20. // Update is called once per frame
  21. void FixedUpdate()
  22. {
  23. Follow();
  24. }
  25. }