Esempio n. 1
0
 public bool Equals(Street obj)
 {
     if (this.points == obj.points) return true;
     return false;
 }
Esempio n. 2
0
        public GameObject NextRandomCheckpoint(GameObject lastCheckpoint, GameObject nextCheckpoint, float speed)
        {
            if (lastCheckpoint == null)
            {
                for (int i = 0; i < streets.Count; i++)
                {
                    if (streets[i].ContentCheckPoint(nextCheckpoint))
                    {
                        return(streets[i].OtherCheckPoint(nextCheckpoint));
                    }
                }
            }
            List <GameObject> targets       = new List <GameObject>();
            Street            currentStreet = FindStreetFromCheckPoint(nextCheckpoint, lastCheckpoint);

            bool direction = false;

            if (currentStreet.CheckPointIndex(nextCheckpoint) == 1)
            {
                direction = true;
            }

            int           checkPointIntersect = 1;
            List <Street> intersectStreet     = new List <Street>();

            if (!direction)
            {
                checkPointIntersect = 0;
            }
            foreach (Street street in streets)
            {
                if (street == currentStreet)
                {
                    continue;
                }
                if (street.ContentCheckPoint(currentStreet.points[checkPointIntersect]))
                {
                    intersectStreet.Add(street);
                }
            }

            if (intersectStreet.Count == 0)
            {
//                Debug.Log("Not intersect");
                if (currentStreet.IsTwoWay)
                {
                    return(currentStreet.OtherCheckPoint(currentStreet.points[checkPointIntersect]));
                }
                return(null);
            }
            else
            {
                foreach (Street street in intersectStreet)
                {
                    if (street.CanGoIn(currentStreet.points[checkPointIntersect], (int)speed))
                    {
                        targets.Add(street.OtherCheckPoint(currentStreet.points[checkPointIntersect]));
                    }
                }
            }
            if (targets.Count > 0)
            {
                //GameObject streetOnTheRight=
                if (targets.Count > 1)
                {
                    GameObject checkpointOnTheRight = CheckPointOnTheRight(nextCheckpoint, lastCheckpoint);
                    if (checkpointOnTheRight != null)
                    {
                        targets.Remove(checkpointOnTheRight);
                    }
                }
                return(targets[UnityEngine.Random.Range(0, targets.Count)]);
            }
            else
            if (currentStreet.IsTwoWay)
            {
                return(currentStreet.OtherCheckPoint(currentStreet.points[checkPointIntersect]));
            }
            return(null);
        }