12345678910111213141516171819202122232425262728293031323334 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Camera_Script : MonoBehaviour
- {
- public float xMin = float.MinValue;
- public float yMin = -10;
- public float xMax = float.MaxValue;
- public float yMax = float.MaxValue;
- public float xOffset = 0;
- public float yOffset = 1;
- private GameObject player;
- void Start()
- {
- player = GameObject.FindGameObjectWithTag("Player");
- float x = Mathf.Clamp(player.transform.position.x + xOffset, xMin, xMax);
- float y = Mathf.Clamp(player.transform.position.y + yOffset, yMin, yMax);
- gameObject.transform.position = new Vector3(x, y, gameObject.transform.position.z);
- }
- void LateUpdate()
- {
- float x = Mathf.Clamp(((player.transform.position.x + xOffset + gameObject.transform.position.x * 7) / 8), xMin, xMax);
- float y = Mathf.Clamp(((player.transform.position.y + yOffset + gameObject.transform.position.y * 2.975f) / 4), yMin, yMax);
- gameObject.transform.position = new Vector3(x, y, gameObject.transform.position.z);
- }
- }
|