Итак, мой друг, я попытался сделать канон, который в единстве 3d с прямоугольниками и окружностью.Мы хотим ограничить угол поворота канона более -90 градусами и менее 0 градусов.Вот коды:
Но при игре в игру канон поворачивается более чем на минус девяносто градусов и падает с земли.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private float rotation = 0f;
public GameObject wheele;
private float xMin = -1.0f, xMax = 1.0f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
if (rotation >= -90)
transform.parent.transform.Rotate(new Vector3(0.0f, 0.0f, rotation));
rotation -= 8;
//Mathf.Clamp(rotation, -90.0f, 0);
}
if(Input.GetKeyDown(KeyCode.DownArrow))
{
if (rotation >= -90)
transform.parent.transform.RotateAround(wheele.transform.position, Vector3.up,20);
rotation += 2;
Mathf.Clamp(rotation, -90.0f, 0);
}
}
}
Как вы можете видеть на следующем рисунке:
![enter image description here](https://i.stack.imgur.com/rl8eo.png)