private void OnTriggerEnter(Collider other) { StopCoroutine("Bounce"); if (targetList.Count - 1 < extraTarget) { if (other.gameObject.tag == "Enemy" && !targetList.Exists(o => o == other.gameObject)) { Destroy(gameObject.GetComponent <SphereCollider>()); targetList.Add(other.gameObject); LightningChain lightning = Instantiate(this.lightning); if (lastTarget != null) { lightning.SetChain(lastTarget.transform, targetList[targetList.Count - 1].transform); } else { GameObject deadPoint = new GameObject("DeadPoint"); deadPoint.transform.position = lastTargetPosition; lightning.SetChain(deadPoint.transform, targetList[targetList.Count - 1].transform); } lastTarget = targetList[targetList.Count - 1]; lastTargetPosition = lastTarget.transform.position; transform.position = other.gameObject.transform.position; Destroy(lightning.gameObject, 0.5f); targetList[targetList.Count - 1].GetComponent <Enemy>().TakeDamage(damage); } } StartCoroutine("Bounce"); }
public override void Attack() { if (attackTimer >= attackRate) { attackTimer = 0; LightningChain lightning = Instantiate(this.lightning); lightning.SetChain(firePositon.transform, enemyList[0].transform); Destroy(lightning.gameObject, 0.5f); GameObject bouncer = new GameObject("Empty"); bouncer.transform.position = enemyList[0].transform.position; bouncer.AddComponent <LightningBouncer>(); bouncer.GetComponent <LightningBouncer>().SetBouncer(damage, extraTarget, bounceRange, this.lightning, enemyList[0]); enemyList[0].GetComponent <Enemy>().TakeDamage(damage); } }