コード例 #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
            {
            }
        }
    }
コード例 #2
0
    //if the car infront or around you changes it's light change yours as well
    private void OnTriggerStay(Collider other)
    {
        if (other.gameObject.tag == "trafficLight")
        {
            //change depending on traffic light if you're staying in it
            bool changeTo = other.gameObject.GetComponent <TrafficLightScript>().greenLight;
            trafficStop = !changeTo;
            stop        = !changeTo;
        }
        else if (other.gameObject.tag == "avatar")
        {
            Trigger hit = other.gameObject.GetComponent <Trigger>();
            trafficStop = hit.trafficStop;
            if (stop)
            {
                return;
            }


            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 == "bus")
        {
            BusTrigger diffHit = other.gameObject.GetComponent <BusTrigger>();
            trafficStop = diffHit.trafficStop;
        }
    }
コード例 #3
0
    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
            {
            }
        }
    }