Unity动画C#

时间:2017-01-09 20:23:36

标签: c# animation unity3d reference

我正在为游戏制作能力,我需要添加动画(我知道该怎么做)。我的问题是我需要一种方法来引用动画而不分配特定的动画。我有一个基类和一个能力的基础逻辑(这是我需要一般参考,因为一个能力确实需要一个动画)然后当我想要一个能力我创建一个继承基础的新类,然后创建这种方式的能力(我将分配动画的地方)。

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

1 个答案:

答案 0 :(得分:0)

ArrayList<BarEntry> entries1 = new ArrayList<BarEntry>(); ArrayList<BarEntry> entries2 = new ArrayList<BarEntry>(); for (int index = 0; index < itemcount; index++) { entries1.add(new BarEntry(0, getRandom(25, 25))); // stacked entries2.add(new BarEntry(0, new float[]{getRandom(13, 12), getRandom(13, 12)})); } BarDataSet set1 = new BarDataSet(entries1, "Bar 1"); set1.setColor(Color.rgb(60, 220, 78)); set1.setValueTextColor(Color.rgb(60, 220, 78)); set1.setValueTextSize(10f); set1.setAxisDependency(YAxis.AxisDependency.LEFT); BarDataSet set2 = new BarDataSet(entries2, ""); set2.setStackLabels(new String[]{"Stack 1", "Stack 2"}); set2.setColors(new int[]{Color.rgb(61, 165, 255), Color.rgb(23, 197, 255)}); set2.setValueTextColor(Color.rgb(61, 165, 255)); set2.setValueTextSize(10f); set2.setAxisDependency(YAxis.AxisDependency.LEFT); float groupSpace = 0.06f; float barSpace = 0.02f; // x2 dataset float barWidth = 0.45f; // x2 dataset // (0.45 + 0.02) * 2 + 0.06 = 1.00 -> interval per "group" BarData d = new BarData(set1); d.setBarWidth(barWidth); // make this BarData object grouped d.groupBars(0, groupSpace, barSpace); // start at x = 0 控制您的所有对象动画和状态,如果它附加到您的Animator Component,您可以像这样获得对它的引用

gameobject

如果您愿意,您的班级也可以是public class player: MonoBehaviour { public Animator anim; public void Start() { anim = GetComponent<Animator>(); } } ,只需调用子类中基类的开头即可获得对abstract的引用

animator component
相关问题