2017-01-09 28 views
1

我正在制作游戏的能力,我需要添加动画(我知道该怎么做)。我的问题是我需要一种方法来创建动画的引用,而无需分配特定的动画。我有一个基类以及一个基础逻辑(这是我需要一个通用引用的地方,因为一个异能需要一个动画),然后当我想创造一个能力时,我创建一个新的类继承基础,然后创建这种能力(这是我将分配动画的地方)。团结动画C#

//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; 
     } 
    } 
} 
+0

是否使用Mecani米到动画? –

+0

如果您知道如何进行动画制作,那么该学习使用Mecanim参数和事件了。 – Vancete

+0

@SergioOrmeño我使用Blender制作动画,然后将其导出为.fbx文件 –

回答

0

Animator Component控制所有对象的动画和状态,如果它连接到您的gameobject你可以对它的引用这样

public class player: MonoBehaviour { 
    public Animator anim;  
    public void Start() { 
     anim = GetComponent<Animator>(); 
    } 
} 

类,也可以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();   
    } 
} 
+0

这看起来很有前途,我会试试看。谢谢! –

+0

这根据需要工作。谢谢! –