Beispiel #1
0
    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);
            }
        }
    }
Beispiel #2
0
    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;
        }
    }
Beispiel #3
0
    IEnumerator DelayedDestoryDelegate()
    {
        yield return(new WaitForSeconds(livingTime));

        explodeLink.CasterDelegateDestroy(transform.position);
    }