[英]Unity Animations C#
I am making abilities for a game and I need to add animations (which I know how to do). 我正在为游戏制作能力,我需要添加动画(我知道该怎么做)。 My problem is I need a way to make a reference to animations without assigning a particular animation.
我的问题是我需要一种方法来引用动画而不分配特定的动画。 I have a base class along with base logic for an ability (which is where I need a general reference because an ability does need an animation) and then when I want to make an ability I make a new class that inherits the base and then create the ability that way (which is where I would assign an animation).
我有一个基类和一个能力的基础逻辑(这是我需要一般参考,因为一个能力确实需要一个动画)然后当我想要一个能力我创建一个继承基础的新类,然后创建这种方式的能力(我将分配动画的地方)。
//Default logic for abilities
public virtual void abilityEffects(hero caster, hero target){
this.caster = caster;
this.target = target;
float DMG = damage * this.caster.heroAttPow;
//Ability should not be on cooldown the first time it is used
if (firstUse == true)
{
//sets the total damage to take into account the ability damage plus the hero power
//need general reference to animation here
//when animation is over, deal damage
this.target.HP -= DMG;
firstUse = false;
//cooldown begins
SpellStart = Time.time;
}
if(firstUse == false)
{
if (Time.time > SpellStart + SpellCooldown)
{
//sets the total damage to take into account the ability damage plus the hero power
//need general reference to animation here
//when animation is over, deal damage
this.target.HP -= DMG;
//cooldown begins
SpellStart = Time.time;
}
}
}
an Animator Component
controls all your object animations and states and if it is attached to your gameobject
you can get a reference to it like this Animator Component
控制所有对象动画和状态,如果它附加到您的gameobject
您可以像这样引用它
public class player: MonoBehaviour {
public Animator anim;
public void Start() {
anim = GetComponent<Animator>();
}
}
your class can also be abstract
if you want to you just should call the start of the base class in the child class to get the reference to the animator component
你的类也可以是
abstract
如果你想要你应该在子类中调用基类的开头来获取对animator component
的引用
public abstract class player: MonoBehaviour {
public Animator anim;
public void Start() {
anim = GetComponent<Animator>();
}
}
public class PlayerChild: player{
void Start() {
base.Start();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.