unity3d MouseLook 如何当单击左键移动鼠标才能实现上下左右全方位旋转
unity3d第一人称控制器里MouseLook脚本,在默认情况下移动鼠标可以上下左右全方位旋转。如何当单击左键移动鼠标才能实现上下左右全方位旋转,松开鼠标左键禁止全方位...
unity3d 第一人称控制器里MouseLook脚本,在 默认情况下移动鼠标可以上下左右全方位旋转。如何当单击左键移动鼠标才能实现上下左右全方位旋转,松开鼠标左键禁止全方位旋转,或者有已经改好的脚本,给个下载链接谢谢了
源代码
using UnityEngine;
using System.Collections;
/// MouseLook rotates the transform based on the mouse delta.
......
[AddComponentMenu("Camera-Control/Mouse Look")]
public class MouseLook : MonoBehaviour {
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX = 15F;
public float sensitivityY = 15F;
...... 展开
源代码
using UnityEngine;
using System.Collections;
/// MouseLook rotates the transform based on the mouse delta.
......
[AddComponentMenu("Camera-Control/Mouse Look")]
public class MouseLook : MonoBehaviour {
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX = 15F;
public float sensitivityY = 15F;
...... 展开
3个回答
展开全部
在那个脚本前面加上一个判断就行了,if(Input.GetMouseButton(0)){ 旋转代码}
追问
具体应该加到哪里呢?我试了下,加了后运行不了。我把原代码补充到问题里你看看
追答
你只把旋转的代码放到if里面就行
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public void LookRotation(Transform character, Transform camera)
{
if (Input.GetMouseButton (0))
{
float yRot = CrossPlatformInputManager.GetAxis ("Mouse X") * XSensitivity;
float xRot = CrossPlatformInputManager.GetAxis ("Mouse Y") * YSensitivity;
m_CharacterTargetRot *= Quaternion.Euler (0f, yRot, 0f);
m_CameraTargetRot *= Quaternion.Euler (-xRot, 0f, 0f);
if (clampVerticalRotation)
m_CameraTargetRot = ClampRotationAroundXAxis (m_CameraTargetRot);
if (smooth) {
character.localRotation = Quaternion.Slerp (character.localRotation, m_CharacterTargetRot,
smoothTime * Time.deltaTime);
camera.localRotation = Quaternion.Slerp (camera.localRotation, m_CameraTargetRot,
smoothTime * Time.deltaTime);
} else {
character.localRotation = m_CharacterTargetRot;
camera.localRotation = m_CameraTargetRot;
}
}
}
{
if (Input.GetMouseButton (0))
{
float yRot = CrossPlatformInputManager.GetAxis ("Mouse X") * XSensitivity;
float xRot = CrossPlatformInputManager.GetAxis ("Mouse Y") * YSensitivity;
m_CharacterTargetRot *= Quaternion.Euler (0f, yRot, 0f);
m_CameraTargetRot *= Quaternion.Euler (-xRot, 0f, 0f);
if (clampVerticalRotation)
m_CameraTargetRot = ClampRotationAroundXAxis (m_CameraTargetRot);
if (smooth) {
character.localRotation = Quaternion.Slerp (character.localRotation, m_CharacterTargetRot,
smoothTime * Time.deltaTime);
camera.localRotation = Quaternion.Slerp (camera.localRotation, m_CameraTargetRot,
smoothTime * Time.deltaTime);
} else {
character.localRotation = m_CharacterTargetRot;
camera.localRotation = m_CameraTargetRot;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询