protected void OnHit(EventInfoList infoList, Target target) { if (this.isDead) { return; } foreach (EventInfo info in infoList) { switch (info.name) { case "Damage": this.life -= (int)info.value; break; } } if (this.life <= 0) { this.isDead = true; Instantiate ( this.explosion.gameObject, this.transform.position, this.transform.rotation ); this.gameObject.SetActive(false); } }
/// <summary> /// Triggered when a target is hit /// </summary> /// <param name="source">The EventInfoList to send</param> /// <param name="source"> /// The target struct used to cache this target when sent /// </param> public void OnHit(EventInfoList eventInfoList, Target target) { #if UNITY_EDITOR // Normal level debug and above if (this.debugLevel > DEBUG_LEVELS.Off) { Debug.Log ( string.Format ( "Targetable ({0}): EventInfoList[{1}]", this.name, eventInfoList.ToString() ) ); } #endif // Set the hitTime for all eventInfos in the list. eventInfoList = eventInfoList.CopyWithHitTime(); if (this.onHitDelegates != null) { this.onHitDelegates(eventInfoList, target); } }
/// <summary> /// Get a copy of this list with effectInfo.hitTime set to 'now'. /// </summary> /// <returns>EventInfoList</returns> public EventInfoList CopyWithHitTime() { var newlist = new EventInfoList(); EventInfo info; IEnumerator <EventInfo> enumerator = base.GetEnumerator(); while (enumerator.MoveNext()) { info = enumerator.Current; info.hitTime = Time.time; newlist.Add(info); } return(newlist); }
protected void OnHit(EventInfoList infoList, Target target) { // If dead, then all done! Will also interupt the co-routine. if (this.currentState == STATES.Dead) { return; } if (target.collider != null) { Debug.Log(this.name + " was hit by 3D collider on " + target.collider.name); } #if (!UNITY_4_0 && !UNITY_4_0_1 && !UNITY_4_1 && !UNITY_4_2) // Unity 4.3+ only... if (target.collider2D != null) { Debug.Log(this.name + " was hit by 2D collider on " + target.collider2D.name); } #endif foreach (EventInfo info in infoList) { switch (info.name) { case "Damage": this.life -= (int)info.value; break; } } if (this.life <= 0) { this.SetState(STATES.Dead); Instantiate ( this.explosion.gameObject, this.transform.position, this.transform.rotation ); Destroy(this.gameObject); } }
public EventInfoList(EventInfoList eventInfoList) : base(eventInfoList) { }