Después de estudiar los artículos de varios grandes, escribí estas tres líneas de código
Simplemente cuélgalo en el objeto de destino, puedes reconocer la cámara principal por ti mismo
La función es controlar las direcciones positiva y negativa, y puede rotar con un eje fijo.Actualmente, el eje y sigue a la cámara.
El control positivo y negativo puede ser el mismo que la primera línea del código *-1, este código no parece ser bueno en la situación actual de la vista superior, se pueden encontrar otros problemas en la práctica
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LookAtview : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
private void Update()
{
//看向的位置 可以控制正负
this.transform.LookAt(Camera.main.transform.position*-1);//控制正负
//相对位置
this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(Camera.main.transform.position - this.transform.position), 0);
//确定变化的轴
this.transform.rotation = new Quaternion(0, this.transform.rotation.y, 0, this.transform.rotation.w);
}
}
Gracias a esos grandes que compartieron sus conocimientos, ¡muchas gracias! También comparto mi humilde opinión.