【发布时间】:2015-11-28 21:28:52
【问题描述】:
我正在关注YouTube 上有关使用混合树的播放器动画的视频教程。我按照那个人的教程去喝茶,我在控制台中没有收到任何错误,唯一的问题是,当我玩游戏时,无论我点击多少次,我的播放器都没有播放动画。我为我的玩家创建了一个点击移动脚本(c#)来移动,并且(如上所述)完全按照这个人的教程进行操作。我检查了动画窗口(在玩游戏时),看到我的播放器空闲状态仍在播放,而不是在播放行走状态,无论我移动到哪里。我想可能是因为:
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target.z = transform.position.z;
}
transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
}
但我不是天才!我想要的是让我的播放器完全按照视频教程所做的,但使用 (Input.GetMouseButtonDown(0))。谁能帮我解决我的问题!谢谢,这是我的完整代码:
using UnityEngine;
using System.Collections;
public class move : MonoBehaviour
{
private Animator anim;
public float speed = 15f;
private Vector3 target;
void Start ()
{
target = transform.position;
anim = GetComponent<Animator> ();
}
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
target.z = transform.position.z;
}
transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
float inputX = Input.GetAxis ("Horizontal");
float inputY = Input.GetAxis ("Vertical");
anim.SetFloat ("SpeedX", inputX);
anim.SetFloat ("SpeedY", inputY);
}
void FixedUpdate ()
{
float LastInputX = Input.GetAxis ("Horizontal");
float LastInputY = Input.GetAxis ("Vertical");
if (LastInputX != 0 || LastInputY != 0) {
anim.SetBool ("walking", true);
if (LastInputX > 0) {
anim.SetFloat ("LastMoveX", 1f);
} else if (LastInputX < 0) {
anim.SetFloat ("LastMoveX", -1f);
} else {
anim.SetBool ("walking", false);
}
if (LastInputY > 0) {
anim.SetFloat ("LastMoveY", 1f);
} else if (LastInputY < 0) {
anim.SetFloat ("LastMoveY", -1f);
} else {
anim.SetFloat ("LastMoveY", 0f);
}
} else {
anim.SetBool ("walking", false);
}
}
【问题讨论】: