unity 2D 播放器运动参数不存在 [英] unity 2D player movement parameters do not exist

查看:50
本文介绍了unity 2D 播放器运动参数不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设法制作了一个自上而下的射击游戏,现在我正在研究动画.我已经关注了 pixelnest.io 的几个教程,但奇怪的是我收到一条错误消息,说参数‘moveRight’不存在.统一动画对我来说是全新的,我一直在尝试尽可能多地阅读.任何修复动画以便在我向右移动时播放的建议?下面是一些图片和我的代码.

I've managed to make a little top down shooter now I'm going over animations. I have followed a couple tutorials by pixelnest.io but strangly I'm getting an error saying "parameter 'moveRight' does not exist. animation in unity is completely new to me and have been trying to read up as much as I can. any suggestions to fix the animation so it plays when I move right? below are some pictures and my code.

using UnityEngine;

使用 System.Collections;

using System.Collections;

公共类 playerMove : MonoBehaviour {

public class playerMove : MonoBehaviour {

public float maxSpeed = 5f;
Animator animator;
bool isRight;

void Awake(){
    animator = GetComponent<Animator>();
}

void Update(){
    Vector3 posMove = transform.position;
    Vector3 velocityH = new Vector3 (Input.GetAxis ("Horizontal") * maxSpeed * Time.deltaTime, 0, 0);
    //this is just test a before i add it to the right movement
    animator.SetBool ("moveRight", isRight);


    Vector3 velocityV = new Vector3 (0, Input.GetAxis ("Vertical") * maxSpeed * Time.deltaTime, 0);
    posMove += velocityH + velocityV;
    transform.position = posMove;
}

}

推荐答案

这是因为您的动画师中没有名为moveRight"的布尔值.
查看您发布的第一个屏幕截图.在左下角,您已经声明了一个名为isRight"的布尔值.

This is because you don't have a boolean called "moveRight" in your animator.
Look at the first screenshot you posted. In the bottom left corner, you've declared a single boolean named "isRight".

在使用 Animator.SetBool(yourBool, boolValue) 时,您需要传递的第一个参数是动画制作器中声明的布尔值的名称(在本例中,它是isRight").

While using Animator.SetBool(yourBool, boolValue), you first parameter you need to pass is the name of the boolean declared in the animator (in this case, it's "isRight").

更改脚本中的以下代码行

Change the following line of code in your script

改变这一行

animator.SetBool ("moveRight", isRight);

阅读

animator.SetBool ("isRight", isRight);

这篇关于unity 2D 播放器运动参数不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆