SetBool() unity5 的问题 (javascript)
Problems with SetBool() unity5 (javascript)
我一直在进行研究,发现了一些代码可以将布尔参数设置为 true。我查看了 Unity API,这段代码应该可以工作(但没有):
#pragma strict
function Start () {
}
function Update () {
var animator = Animator;
if(Input.GetKeyDown("W") || Input.GetKeyDown("s")){
animator.SetBool("please", true);
}
else{
animator.SetBool("please", false);
}
}
你们知道发生了什么事吗?我不断收到错误消息:'SetBool' 不是 System.type 的成员。
您必须首先检索附加到游戏对象的 Animator 组件。你做错了。此外,最好使用 bool 参数的哈希值而不是其名称,请参见下文。
var animator : Animator ;
var boolHash : int;
function Start () {
animator = GetComponent(Animator) as Animator;
boolHash = Animator.StringToHash("please") ;
}
function Update ()
{
if(Input.GetKeyDown("W") || Input.GetKeyDown("s"))
{
animator.SetBool(boolHash, true);
}
else
{
animator.SetBool(boolHash, false);
}
}
我一直在进行研究,发现了一些代码可以将布尔参数设置为 true。我查看了 Unity API,这段代码应该可以工作(但没有):
#pragma strict
function Start () {
}
function Update () {
var animator = Animator;
if(Input.GetKeyDown("W") || Input.GetKeyDown("s")){
animator.SetBool("please", true);
}
else{
animator.SetBool("please", false);
}
}
你们知道发生了什么事吗?我不断收到错误消息:'SetBool' 不是 System.type 的成员。
您必须首先检索附加到游戏对象的 Animator 组件。你做错了。此外,最好使用 bool 参数的哈希值而不是其名称,请参见下文。
var animator : Animator ;
var boolHash : int;
function Start () {
animator = GetComponent(Animator) as Animator;
boolHash = Animator.StringToHash("please") ;
}
function Update ()
{
if(Input.GetKeyDown("W") || Input.GetKeyDown("s"))
{
animator.SetBool(boolHash, true);
}
else
{
animator.SetBool(boolHash, false);
}
}