void OnTriggerEnter(Collider other) { // avoid collider with self if (other.gameObject.tag == TagList.Wall) { Instantiate(explosion, transform.position, Quaternion.identity); Destroy(gameObject); } ExplodeLink explodeLink = GetComponent <ExplodeLink>(); if (explodeLink && other.gameObject.GetInstanceID() == explodeLink.caster.GetInstanceID()) { // nothing should happen return; } // if other got a explodelink as well. // Then we want to identify whether they are from same guy ExplodeLink otherExplodeLink = other.GetComponent <ExplodeLink>(); if (otherExplodeLink && otherExplodeLink.caster.GetInstanceID() == explodeLink.caster.GetInstanceID()) { // nothing should happen return; } if ((other.gameObject.tag == TagList.Player || (other.gameObject.tag == TagList.Fireball && !bigger)) && // the bigger fireball cannot be destoried by any other spells. isMoving) { isMoving = false; // Cause Explosion Here // Debug.Log ("Knocked On other, explode now"); Debug.DrawLine(transform.position, new Vector3(transform.position.x, 30.0f, transform.position.z), Color.red, 10.0f); if (explodeLink) { explodeLink.CasterDelegateDestroy(transform.position); } else { // no caster delegate Instantiate(explosion, transform.position, Quaternion.identity); Destroy(gameObject); } } }
void Start() { explodeLink = GetComponent <ExplodeLink> (); if (explodeLink) { StartCoroutine(DelayedDestoryDelegate()); } else { Destroy(gameObject, livingTime); } }
public override IEnumerator castMagic(GameObject caster, Vector3 hitpoint = default(Vector3)) { // Debug.Log("Fireball Activiated!"); // float transformed_angle = Vector3.Angle (new Vector3 (0, 0, 1), hitpoint-caster.transform.position); // // Debug.Log ("Angle: " + transformed_angle); Quaternion lookedQua = Quaternion.LookRotation(hitpoint - caster.transform.position); for (int i = 0; i < NumberOfBalls; i++) // TODO num of fireballs { float randomAngle = Random.Range(-1 * Range, Range); // TODO range angles GameObject gb = GameObject.Instantiate(fireball, caster.transform.position, lookedQua) as GameObject; // add caster delegate ExplodeLink explodeLink = gb.GetComponent <ExplodeLink>(); if (explodeLink) { explodeLink.caster = caster; } else { Debug.LogWarning("[Spell] Spell has no explode delegate"); } // scale ScaleFireball(gb, scale); gb.transform.Rotate(gb.transform.up, randomAngle, Space.Self); MovableUnit movUnit = gb.GetComponent <MovableUnit> (); Vector3 newHitPoint = MathUtil.RotatePointAroundPivot(hitpoint, caster.transform.position, new Vector3(0, randomAngle, 0)); movUnit.MoveTo(newHitPoint); yield return(new WaitForSeconds(TimeInterval)); } // GameObject gb = GameObject.Instantiate (fireball, caster.transform.position, lookedQua) as GameObject; yield return(null); }
void FixedUpdate() { // If the object is already there, explode if ((transform.position - destination).magnitude < 1.0f && isMoving) { isMoving = false; // Cause Explosion Here ExplodeLink explodeLink = GetComponent <ExplodeLink>(); if (explodeLink) { explodeLink.CasterDelegateDestroy(destination); } else { // no caster delegate Instantiate(explosion, destination, Quaternion.identity); Destroy(gameObject); } } // Reflect if speed change // change the orientation for effect glitches if ((GetComponent <Rigidbody>().velocity - curSpeed).magnitude > 0.1f) { // Debug.Log("Rotate Angle: " + Vector3.Angle(curSpeed, rigidbody.velocity)); float angle = Vector3.Angle(curSpeed, GetComponent <Rigidbody>().velocity); Vector3 cross = Vector3.Cross(curSpeed, GetComponent <Rigidbody>().velocity); if (cross.y < 0) { angle = -angle; } transform.Rotate(new Vector3(0, angle, 0)); GetComponent <Rigidbody>().velocity = GetComponent <Rigidbody>().velocity.normalized *speed; // enfore a constant speed curSpeed = GetComponent <Rigidbody>().velocity; } }