动画师设置浮动

时间:2018-11-14 10:54:45

标签: c# unity3d

我是用unity3d开发游戏的初学者。我刚刚找到了移动角色的脚本。因此,我对此脚本有些困惑。这是我不明白的代码。

if (Input.GetAxis ("Vertical") == 0 && Input.GetAxis ("Horizontal") == 0) {

       animator.SetFloat ("PlayerState", IDLE);
}

我不明白这行:animator.SetFloat("PlayerState", IDLE);

什么是PlayerState和IDLE?我知道这是一个参数。 IDLE是变量吗?如何运作?你能启发我吗?

PS:在找到的源代码上,您实际上看不到任何变量。

添加的代码

我不理解的另一个代码。假设玩家按住LShift和W键,那么角色将运行,对吗?脚本如何检查动画制作者是否可以运行角色?另一件事是,由于我有一个值为4f的变量RUN,我将删除行moveSpeed = 4f。还是不?

这是脚本:

if (Input.GetKey (KeyCode.LeftShift)) {
    if (Input.GetAxis ("Vertical") > 0) { 

        moveSpeed = 4f;

        Quaternion turnAngle = Quaternion.Euler (0, centerPoint.eulerAngles.y, 0);
        character.rotation = Quaternion.Slerp (character.rotation, turnAngle, Time.deltaTime * rotationSpeed);
        animator.SetFloat ("PlayerState", RUN);
    }
}

2 个答案:

答案 0 :(得分:3)

文档是您的朋友。 here详细说明了您正在谈论的方法。

基本上,animator变量是对Animator对象的引用,该对象是使用Unity的Animator创建的。这是我正在谈论的菜单的图片。enter image description here

示例代码中的

“ PlayerState”是您在Unity的Animator中创建的条件。在我粘贴的图片中,条件是“ horizo​​ntalSpeed”。 IDLE很可能是在您粘贴的代码中的其他位置定义的,并且必须是将动画设置为IDLE状态的值,例如float IDLE = 0f

答案 1 :(得分:0)

如果我没记错的话!我认为这个 setfloat 函数只能在更新函数中工作。