【发布时间】:2019-12-13 20:50:50
【问题描述】:
玩家是父对象的子对象,玩家有自己的子对象一个相机。 当 Z on Rotation 为 50 且 X 和 Y 为 0 时播放器开始。
然后我使用带有动画的 Player Animator 控制器将 Z 从 50 更改为 0。 游戏开始时,玩家在 Z 轴上从 50 变为 0。
播放器附加了一些组件,我尝试在游戏运行时逐个删除,但没有任何改变/帮助。
播放器附加了刚体和控制器脚本。
Player Camera 附加了一个 Player Camera Controller 脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerCameraController : MonoBehaviour
{
public float sensitivity = 5.0f;
public float smoothing = 2.0f;
private UnityEngine.GameObject player;
private Vector2 mouseLook;
private Vector2 smoothV;
// Use this for initialization
void Start()
{
player = this.transform.parent.gameObject;
}
// Update is called once per frame
void Update()
{
if (PauseManager.gamePaused == false)
{
var md = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
md = Vector2.Scale(md, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
smoothV.x = Mathf.Lerp(smoothV.x, md.x, 1f / smoothing);
smoothV.y = Mathf.Lerp(smoothV.y, md.y, 1f / smoothing);
mouseLook += smoothV;
mouseLook.y = Mathf.Clamp(mouseLook.y, -90f, 90f);
transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
player.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, Vector3.up);
}
}
}
我可以使用鼠标将相机旋转 360 度。 并且只有在使用鼠标时才会改变玩家在 Y 轴上的旋转。
但后来我尝试在游戏运行时为 X Y 和 Z 上的 Player 旋转设置一个新值,但没有任何改变。
由于某种原因,它改变了旋转,我看到播放器使用 Animator 或鼠标旋转,但是当我更改播放器旋转值时,没有任何反应。
我还尝试附加一个简单的脚本进行测试,但按下 L 按钮时没有任何变化:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
private void Update()
{
if (Input.GetKeyDown(KeyCode.L))
{
var player = GameObject.Find("Player");
player.transform.Rotate(Vector3.left, 25);
}
}
}
我不知道如何旋转播放器,为什么我不能自己旋转它,但我可以使用鼠标控制器脚本或动画师?
【问题讨论】: