/// <summary> /// Copy constructor, used to copy abilities to a player /// </summary> /// <param name="jango"></param> public SlowMovement(SlowMovement jango) { _slowAmount = jango._slowAmount; Debug.Log(jango + "cloned."); _lifetime = jango.Lifetime; _tickTime = jango.TickTime; Debug.Log("Lifetime: " + jango.Lifetime + " | " + Lifetime); Debug.Log("Ticktime: " + jango.TickTime + " | " + TickTime); _name = "Slow Movement"; }
/// <summary> /// Copy constructor, used to copy abilities to a player /// </summary> /// <param name="jango"></param> public SlowMovement(SlowMovement jango) { SlowAmount = jango.SlowAmount; Debug.Log(jango + "cloned."); Lifetime = jango.Lifetime; TickTime = jango.TickTime; Debug.Log("Lifetime: " + jango.Lifetime + " | " + Lifetime); Debug.Log("Ticktime: " + jango.TickTime + " | " + TickTime); Name = "Slow Movement"; }
// Serialize Slow private void SerializeAsSlow(SlowMovement effect) { int index = 0; // Allocate space for slow params int sizeofSlow = 4; // One float for slow amount sizeofEffect = sizeofSlow; SerializeBaseEffect(effect, ref index); // Serialization Protocol.Serialize(effect.SlowAmount, effectInfo, ref index); }
/// <summary> /// Copies the effect to a target. Must transfer all values over /// a copy constructor helps with this. /// </summary> /// <param name="target"></param> public override void ApplyEffect(GameObject target) { // Ref the player stat class PlayerStats ps = target.GetComponent <PlayerStats>(); if (!ps) { Debug.LogError("No Player Stats class in target: " + target.name); return; } // Copy this effect to the target. A copy constructor helps with this SlowMovement slow = new SlowMovement(this); // The copy is added to the player ps.AddEffect(slow); // ps.AddEffect(this) // WRONG - will add the original not a copy }
// Use this for initialization void Start() { slow = new SlowMovement(0.25f, 3f); }