2017-01-09 46 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

這根據需要工作。謝謝! –