Example #1
0
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "trafficLight")
        {
            bool changeTo = other.gameObject.GetComponent <TrafficLightScript>().greenLight;
            trafficStop = !changeTo;
            stop        = !changeTo;
        }

        else if (other.gameObject.tag == "bus")
        {
            BusTrigger hit     = other.gameObject.GetComponent <BusTrigger>();
            BusScript  diffHit = hit.GetComponent <BusScript>();


            float distanceMe  = Vector3.Distance(bus.transform.position, bus.nextNode.transform.position);
            float distanceHit = Vector3.Distance(diffHit.transform.position, diffHit.nextNode.transform.position);
            //if collider is closer to goal stop else don't

            //if at the back
            if (distanceMe > distanceHit)
            {
                triggered  = true;
                this.other = other;
                //see if the car infront is at a red light
                stop = true;
            }
            //at the front
            else
            {
            }
        }
    }
    void Start()
    {
        gui = (GUIScript)GameObject.Find ("GUIScript").GetComponent (typeof(GUIScript));
        cessna = (CessnaScript)GameObject.Find ("Cessna").GetComponent (typeof(CessnaScript));
        bus = (BusScript) GameObject.Find ("Bus").GetComponent (typeof(BusScript));

        score = 0;
        state = "putRunway";
    }
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "avatar")
        {
            if (stop)
            {
                return;
            }
            Trigger hit = other.gameObject.GetComponent <Trigger>();
            DiffusionAvatarScript diffHit = hit.diff;
            if (diffHit.nextNode != diff.nextNode)
            {
                return;
            }

            float distanceMe  = Vector3.Distance(diff.avatar.transform.position, diff.nextNode.transform.position);
            float distanceHit = Vector3.Distance(diffHit.avatar.transform.position, diffHit.nextNode.transform.position);
            //if collider is closer to goal stop else don't

            //if at the back
            if (distanceMe > distanceHit && ((diffHit.entering && diff.entering) || (!diffHit.entering && !diff.entering)))
            {
                triggered  = true;
                this.other = other;
                //see if the car infront is at a red light
                stop = true;
            }
            //at the front
            else
            {
            }
        }
        else if (other.gameObject.tag == "trafficLight")
        {
            bool changeTo = other.gameObject.GetComponent <TrafficLightScript>().greenLight;
            trafficStop = !changeTo;
            stop        = !changeTo;
            // randmSwitch = (int)UnityEngine.Random.Range(0f,10f);
        }

        else if (other.gameObject.tag == "trafficSign")
        {
            if (UnityEngine.Random.Range(0.0f, 1f) < other.gameObject.GetComponent <RedirectionSignScript>().chanceToRedirect)
            {
                other.gameObject.GetComponent <RedirectionSignScript>().ReDirect(diff);
            }
        }
        else if (other.gameObject.tag == "bus")
        {
            BusTrigger hit     = other.gameObject.GetComponent <BusTrigger>();
            BusScript  diffHit = hit.GetComponent <BusScript>();


            float distanceMe  = Vector3.Distance(diff.avatar.transform.position, diff.nextNode.transform.position);
            float distanceHit = Vector3.Distance(diffHit.transform.position, diffHit.nextNode.transform.position);
            //if collider is closer to goal stop else don't

            //if at the back
            if (distanceMe > distanceHit)
            {
                triggered  = true;
                this.other = other;
                //see if the car infront is at a red light
                stop = true;
            }
            //at the front
            else
            {
            }
        }
    }