[英]Unity3d Camera rotation not working
我试图让粘在播放器上的相机将其每按Q或E旋转45度,但由于某种原因我无法使其正常工作。 即时通讯使用C#。
using UnityEngine;
using System.Collections;
public class Camera : MonoBehaviour
{
int rotatespeed = 3;
int rotationstart = 90;
public GameObject player;
private Vector3 offset;
// Use this for initialization
void Start()
{
offset = transform.position - player.transform.position;
}
// Update is called once per frame
void LateUpdate() {
transform.position = player.transform.position + offset;
}
void Update()
{
if (Input.GetKey("q"))
{
Camera.main.transform.rotation = Quaternion.Euler(x + 45 , y, z);
}
if (Input.GetKey("e"))
{
Camera.main.transform.rotation = Quaternion.Euler(x - 45, y, z);
}
}
}
旋转时应乘以
if (Input.GetKey("q"))
{
Camera.main.transform.rotation *= Quaternion.Euler(45 , 0, 0);
}
if (Input.GetKey("e"))
{
Camera.main.transform.rotation *= Quaternion.Euler(-45, 0, 0);
}
但这会使它向上和向下查找,如果要左右移动,请使用以下命令
if (Input.GetKey("q"))
{
Camera.main.transform.rotation *= Quaternion.Euler(0, 45, 0);
}
if (Input.GetKey("e"))
{
Camera.main.transform.rotation *= Quaternion.Euler(0, -45, 0);
}
重要的旁注
请记住,当用户按住GetKey
时, GetKey
将返回true,即使快速按下它,由于其仍为多帧,因此您的相机似乎失去控制。 您很可能希望使用GetKeyDown
,该方法每次用户按下该键时都只会返回true。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.