gpt4 book ai didi

c# - 无法让动画工作。动画师 Setfloat 错误

转载 作者:太空宇宙 更新时间:2023-11-03 10:31:06 27 4
gpt4 key购买 nike

我对 Unity 和一般编码还是陌生的,所以请记住这一点!我也在 Unity 论坛上问过这个问题,但人们告诉我代码应该可以正常编译,而且他们不知所措,所以我希望能在这里找到一些答案!

我试图让我的步行动画在我称之为速度的参数 > 0.1 时播放

我一直收到这个错误,在谷歌搜索后我还是没弄明白。

Assets/Scripts/PlayerMovement.cs(28,26): error CS1061: Type `Animator' does not contain a definition for `SetFloat' and no extension method `SetFloat' of type `Animator' could be found (are you missing a using directive or an assembly reference?)

知道哪里出了问题吗?

这是我的脚本:

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {
public float speed;
public float floatDown;
public Boundary boundary;
Animator animator;

[System.Serializable]
public class Boundary{
public float xMin, xMax, zMin, zMax, yMin, yMax;
}
// Use this for initialization.
void Start () {
gameObject.tag = "Player";
animator = GetComponent<Animator> ();
}

// Update is called once per frame.
void Update () {

//Basic left, right, up, down, movement.
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis ("Jump");
animator.SetFloat ("Speed", moveHorizontal);
Vector3 movement = new Vector3 (moveHorizontal, moveVertical, 0.0f);
GetComponent<Rigidbody>().velocity = movement * speed;

//Clamping so Bubbleboy doesnt exit screen.
GetComponent<Rigidbody>().position = new Vector3
(
Mathf.Clamp (GetComponent<Rigidbody>().position.x, boundary.xMin, boundary.xMax),
Mathf.Clamp (GetComponent<Rigidbody>().position.y, boundary.yMin, boundary.yMax),
Mathf.Clamp (GetComponent<Rigidbody>().position.z, boundary.zMin, boundary.zMax)
);

//Using relativeForce to simulate floating down.
if (Input.GetKey (KeyCode.S)) {
GetComponent<Rigidbody>().AddRelativeForce (0, floatDown, 0);
}
}
}

最佳答案

确保您没有名为“Animator”的脚本。如果您有同名的项目脚本,Unity 会优先选择您的脚本,而不是作为 Unity 一部分的动画师类。

关于c# - 无法让动画工作。动画师 Setfloat 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30192472/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com