Example #1
0
    bool canWeSpawnCops()
    {
        if (r == null)
        {
            r = FindObjectOfType <NewRoad> ();
        }

        spawnTimer -= Time.deltaTime;
        if (spawnTimer <= 0)
        {
            // if (myRF.areBothJunctionsPlayerAccessable())
            //  {
            //   return true;
            //  }

            foreach (NewRoadJunction nrj in r.sectionsInTheRoad)
            {
                if (nrj.playerCarSpawn == true)
                {
                    if (Vector2.Distance(this.transform.position, nrj.startPoint.position) < 3.0f)
                    {
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
Example #2
0
 void Awake()
 {
     me                = this;
     carsInWorld       = new List <GameObject> ();
     patrolCarsInWorld = new List <GameObject> ();
     r = FindObjectOfType <NewRoad> ();
 }
Example #3
0
    Vector3 getPosForCreatingPoliceCar()
    {
        if (r == null)
        {
            r = FindObjectOfType <NewRoad> ();
        }

        NewRoadJunction rj = r.sectionsInTheRoad[Random.Range(0, r.sectionsInTheRoad.Count)];

        Vector3 start = rj.startPoint.position;
        Vector3 end   = rj.potentialPoints[Random.Range(0, rj.potentialPoints.Count)].transform.position;

        Vector3 dir = end - start;

        return(start + (Random.Range(0.0f, 1.0f) * dir.normalized));


        bool junctionUnavailable = false;

        //if (copCarsAvailable.Count > 0) {
        foreach (GameObject g in copCarsInWorld)
        {
            if (Vector2.Distance(rj.startPoint.position, g.transform.position) < 4 && Vector2.Distance(rj.startPoint.transform.position, CommonObjectsStore.player.transform.position) < 12)
            {
                junctionUnavailable = true;
                //int r2 = Random.Range (0, copCarsAvailable.Count);
                //Vector3 p = copCarsAvailable [r2].transform.position;
                //copCarsAvailable.RemoveAt (r2);
                //return p;
            }
        }
        //}
        if (junctionUnavailable == false)
        {
            return(rj.startPoint.position);
        }
        else
        {
            return(getPosForCreatingPoliceCar());
        }


        return(rj.startPoint.position);

        //List<NewRoadJunction> candidates = new List<NewRoadJunction> ();
        //foreach (NewRoadJunction rj in r.sectionsInTheRoad) {
        //if(rj.playerCarSpawn==true)
        //	{
        //}
    }
Example #4
0
    // Use this for initialization
    void Start()
    {
        if (hasDriver == false)
        {
            foreach (Light l in headlights)
            {
                l.enabled = false;
            }

            foreach (Light l in brakelights)
            {
                l.enabled = false;
            }
        }
        r         = FindObjectOfType <NewRoad> ();
        rid       = this.GetComponent <Rigidbody2D> ();
        nr        = r.getNearestRoad(this.transform.position);
        nextJunct = nr.potentialPoints [Random.Range(0, nr.potentialPoints.Count)];
    }