public SpellFX StartSpell(Transform centerOfCast) { SpellFX fx = Create().GetComponent <SpellFX>(); fx.centerOfSpell = centerOfCast; //this.gameObject.SetActive(true); fx.SpellStart = true; return(this); }
private IEnumerator ChargeCoroutine(Transform SpellOrb, Transform Caster, Stats casterStats, Action action) { float startTime = Time.realtimeSinceStartup; AnimInfo.Activated = true; casterStats.EnergyRegenPause = true; SpellFX newFx = OnActivateFX[0].StartSpell(SpellOrb); GrowingOrbAnimation goa = newFx.GetComponent <GrowingOrbAnimation>(); goa.GrowingBallParent = this; //foreach(SpellFX fx in OnActivateFX) // fx.StartSpell(SpellOrb); StartCoroutine(ChargeAnimationInfoCoroutine(startTime)); // If not enough energy for the full cast float negativeEnergy = casterStats.ConsumeEnergy(ActivationCost); if (negativeEnergy > 0) { AnimInfo.NegativeEnergyCast = true; } float dt = 0; float charge = 0; // Wait till button is released while (action.IsDown() || AnimInfo.NegativeEnergyCast) { dt = Time.realtimeSinceStartup - startTime; if (dt > StartupTime) { AnimInfo.State = AnimationInfo.AnimState.Overcharging; // reduce energy } yield return(null); } AnimInfo.InputReleased = true; dt = Time.realtimeSinceStartup - startTime; // Wait atleast till startupTime if (dt < StartupTime) { yield return(new WaitForSeconds(StartupTime - dt)); } // Dt and charge calculation if (AnimInfo.State == AnimationInfo.AnimState.Overcharging) { charge = AnimInfo.AnimStateProgress; } // Gather Direction Vector3 dir = SpellOrb.position - Caster.position; dir.Normalize(); // Consume energy and launch casterStats.ConsumeEnergy(FullChargeCost * charge); Bullet bullet = Bullet.Launch(SpellOrb.position, dir, Mathf.Lerp(MinDamage, MaxDamage, charge)); float scale = minSize + (maxSize - minSize) * charge; bullet.transform.localScale = new Vector3(scale, scale, scale); AnimInfo.State = AnimationInfo.AnimState.Cooldown; coolDownStarted = Time.realtimeSinceStartup; casterStats.EnergyRegenPause = false; // Replace by Cooldown Animation Handler yield return(new WaitForSeconds(CooldownTime)); resetAnimationInfo(); }
// Use this for initialization void Start() { //gb = gameObject.GetComponent<GrowingBall>(); fx = gameObject.GetComponent <SpellFX>(); mat = renderer.material; }