I first got behind this engine and found a script for a free camera, so I need to limit it along the z, y, and x axes. I donβt want the object to fly beyond the limits I set. The camera itself:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraFly : MonoBehaviour { public float mouseSensitivity = 3.0f; public float speed = 2.0f; private Vector3 transfer; public float minimumX = -360F; public float maximumX = 360F; public float minimumY = -60F; public float maximumY = 60F; float rotationX = 0F; float rotationY = 0F; Quaternion originalRotation; void Start() { originalRotation = transform.rotation; } void Update() { // ΠΠ²ΠΈΠΆΠ΅Π½ΠΈΡ ΠΌΡΡΠΈ -> ΠΡΠ°ΡΠ΅Π½ΠΈΠ΅ ΠΊΠ°ΠΌΠ΅ΡΡ rotationX += Input.GetAxis("Mouse X") * mouseSensitivity; rotationY += Input.GetAxis("Mouse Y") * mouseSensitivity; rotationX = ClampAngle (rotationX, minimumX, maximumX); rotationY = ClampAngle (rotationY, minimumY, maximumY); Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up); Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left); transform.rotation = originalRotation * xQuaternion * yQuaternion; // ΠΏΠ΅ΡΠ΅ΠΌΠ΅ΡΠ΅Π½ΠΈΠ΅ ΠΊΠ°ΠΌΠ΅ΡΡ transfer = transform.forward * Input.GetAxis("Vertical"); transfer += transform.right * Input.GetAxis("Horizontal"); transform.position += transfer * speed * Time.deltaTime; } public static float ClampAngle (float angle, float min, float max) { if (angle < -360F) angle += 360F; if (angle > 360F) angle -= 360F; return Mathf.Clamp (angle, min, max); } }
Regarding the limitation of the review, everything is clear, there are public class variables. I would like something like Π΅ΡΠ»ΠΈ ΠΏΠΎΠ·ΠΈΡΠΈΡ.ΠΊΠ°ΠΌΠ΅ΡΠ°.Ρ
= Π½ΡΠΆΠ½ΠΎΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ ΠΏΠΎ x => Π΄Π²ΠΈΠ³Π°ΡΡ ΠΊΠ°ΠΌΠ΅ΡΡ Π² Π½ΡΠΆΠ½ΠΎΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ ΠΏΠΎ x
. Do something like a dead end. I will be glad to any help.