C# 通过脚本更改动画速度? 公共类门:单一行为 { 无效对撞机(对撞机obj) { var thedoor=GameObject.FindWithTag(“SF_门”); 动画; anim=thedoor.GetComponent(); 动画[“打开”]。速度=10; thedoor.GetComponent()播放(“打开”); } void OnTriggerExit(对撞机obj) { var thedoor=GameObject.FindWithTag(“SF_门”); thedoor.GetComponent().Play(“close”); } }
我试图添加这一部分:C# 通过脚本更改动画速度? 公共类门:单一行为 { 无效对撞机(对撞机obj) { var thedoor=GameObject.FindWithTag(“SF_门”); 动画; anim=thedoor.GetComponent(); 动画[“打开”]。速度=10; thedoor.GetComponent()播放(“打开”); } void OnTriggerExit(对撞机obj) { var thedoor=GameObject.FindWithTag(“SF_门”); thedoor.GetComponent().Play(“close”); } },c#,unity3d,unity5,C#,Unity3d,Unity5,我试图添加这一部分: public class door : MonoBehaviour { void OnTriggerEnter(Collider obj) { var thedoor = GameObject.FindWithTag("SF_Door"); Animation anim; anim = thedoor.GetComponent<Animation>(); anim["open"].
public class door : MonoBehaviour
{
void OnTriggerEnter(Collider obj)
{
var thedoor = GameObject.FindWithTag("SF_Door");
Animation anim;
anim = thedoor.GetComponent<Animation>();
anim["open"].speed = 10;
thedoor.GetComponent<Animation>().Play("open");
}
void OnTriggerExit(Collider obj)
{
var thedoor = GameObject.FindWithTag("SF_Door");
thedoor.GetComponent< Animation > ().Play("close");
}
}
动画动画;
anim=thedoor.GetComponent();
动画[“打开”]。速度=10;
我想让门开得更快,但上面的代码并没有改变速度。
有没有办法不用在编辑器的Animator/Animation窗口中更改/添加内容而通过脚本完成此操作?首先,您需要停止使用动画。取而代之的是将Mecaim与它的Animator组件一起使用。这里有一个像样的介绍 最简单的方法是在
AnimatorController
中添加一个新的float
参数-我们称之为speedMultiplier
,然后在AnimatorController
中选择要加速的动画并按如下方式设置:
现在,不要执行anim[“open”]。速度=…
只需执行以下操作:
Animation anim;
anim = thedoor.GetComponent<Animation>();
anim["open"].speed = 10;
Animator anim=thedoor.GetComponent();
动画设置浮点(“速度倍增器”,10);
这样,动画速度将乘以您为
speedMultiplier
设置的任何值。首先,您需要停止使用动画。取而代之的是将Mecaim与它的Animator组件一起使用。这里有一个像样的介绍
最简单的方法是在AnimatorController
中添加一个新的float
参数-我们称之为speedMultiplier
,然后在AnimatorController
中选择要加速的动画并按如下方式设置:
现在,不要执行anim[“open”]。速度=…
只需执行以下操作:
Animation anim;
anim = thedoor.GetComponent<Animation>();
anim["open"].speed = 10;
Animator anim=thedoor.GetComponent();
动画设置浮点(“速度倍增器”,10);
这样,动画速度将乘以为speedMultiplier
Add“.0f”设置的任何值,因为它是一个浮点值
Animator anim = thedoor.GetComponent<Animator>();
anim.SetFloat("speedMultiplier", 10);
添加“.0f”,因为它是一个浮点数
Animator anim = thedoor.GetComponent<Animator>();
anim.SetFloat("speedMultiplier", 10);
在使用这段代码之前,应该使用
Animator
组件而不是Animation
组件来播放动画<代码>动画组件将随时被删除。在使用此代码进行过度操作之前,应使用动画制作程序
组件而不是动画
组件来播放动画<“代码>动画”组件将随时被删除。问题是,层次结构中的门对象根本没有附加“动画制作”组件,只有“动画组件”。这不是我的预制房。此外,在项目中的预设中,它本身也没有动画师组件。这就是我在脚本中使用动画组件的原因。只需将动画替换为Animator,并为其创建AnimatorController。问题是,层次中的门对象根本没有附加Animator组件,只有动画组件。这不是我的预制房。此外,在项目中的预设中,它本身也没有动画师组件。这就是我在脚本中使用动画组件的原因。只需将动画替换为Animator并为其创建AnimatorController。