Camera_Script.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Camera_Script : MonoBehaviour
  5. {
  6. public float xMin = float.MinValue;
  7. public float yMin = -10;
  8. public float xMax = float.MaxValue;
  9. public float yMax = float.MaxValue;
  10. public float xOffset = 0;
  11. public float yOffset = 1;
  12. private GameObject player;
  13. void Start()
  14. {
  15. player = GameObject.FindGameObjectWithTag("Player");
  16. float x = Mathf.Clamp(player.transform.position.x + xOffset, xMin, xMax);
  17. float y = Mathf.Clamp(player.transform.position.y + yOffset, yMin, yMax);
  18. gameObject.transform.position = new Vector3(x, y, gameObject.transform.position.z);
  19. }
  20. void LateUpdate()
  21. {
  22. float x = Mathf.Clamp(((player.transform.position.x + xOffset + gameObject.transform.position.x * 7) / 8), xMin, xMax);
  23. float y = Mathf.Clamp(((player.transform.position.y + yOffset + gameObject.transform.position.y * 2.975f) / 4), yMin, yMax);
  24. gameObject.transform.position = new Vector3(x, y, gameObject.transform.position.z);
  25. }
  26. }