IEnumerator WaitForLoading()
 {
     while (CarUserController.instance == null)
     {
         yield return(new WaitForSeconds(0.2f));
     }
     carUser  = CarUserController.instance;
     isActive = true;
 }
 void Start()
 {
     Player          = GameManager.Player.GetComponent <CarController>();
     PlayerUser      = GameManager.Player.GetComponent <CarUserController>();
     Main.volume     = QuietVolume;
     Jump.volume     = 0;
     Movement.volume = 0;
     ManyCops.volume = 0;
     FewCops.volume  = 0;
 }
Beispiel #3
0
    void Awake()
    {
        GameObject playerObject = Instantiate <GameObject>(PlayerPrefab);

        playerObject.transform.position = StartPosition.position;
        playerObject.transform.rotation = StartPosition.transform.rotation;
        Player = playerObject.GetComponent <CarUserController>();
        Player.ReplaceModel(CarModel);
        StartPosition.gameObject.SetActive(false);
        GameCamera = CameraInstance;
        CameraInstance.GetComponent <CameraControllerTransparency>().target = Player.transform;
        Houses      = HousesInstance;
        PizzaPlaces = PizzaPlacesInstance;
        TrafficCars = TrafficCarsInstance;
        //CameraInstance.GetComponent<CameraController>().target = Player.transform;
    }
 void Awake()
 {
     instance = this;
 }
    IEnumerator FSM()
    {
        GameObject        go = GameObject.FindGameObjectWithTag("Player");
        CarUserController carUserController = null;

        if (go != null)
        {
            Target            = go.transform;
            carUserController = CarUserController.instance;
        }
        while ((Target != null && !carUserController.isDead) || isExternalWaypoint)
        {
            if (!isExternalWaypoint)
            {
                // IF TARGET/PLAYER IN RANGE FIND PATH
                Vector3 tPos   = Target.position;
                Vector3 ownPos = transform.position;
                float   dist   = Vector3.Distance(ownPos, tPos);
                if (dist < ViewDistance)
                {
                    // SET THE WAYPOINTS IN THE WAYPOINTS ARRAY
                    Index start = mapGenerator.WorldPointToMapIndex(ownPos);
                    Index end   = mapGenerator.WorldPointToMapIndex(tPos);
                    if (!end.Equals(LastTargetTile))
                    {
                        List <Index>   path;
                        List <Vector3> pathV = new List <Vector3>();
                        ///TIMER
                        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                        sw.Start();

                        path = PathFinding.FindPath_AStar(start, end, MapGenerator.Instance);

                        if (path != null)
                        {
                            foreach (Index i in path)
                            {
                                Vector3 v = mapGenerator.IndexToWorldLocation(i);
                                v.x += mapGenerator.tileWidth / 2;
                                v.z += mapGenerator.tileHeight / 2;
                                pathV.Add(v);
                            }

                            SimplifyPath_UpdateWaypoints(pathV);
                            //isAllResourceLoaded = true;
                            idealPath = waypoints[0] - transform.position;
                            endOfPath = false;
                        }
                        LastTargetTile = end;

                        ///TIMER
                        sw.Stop();
                        Debug.Log("Time Elapsed: " + sw.ElapsedMilliseconds + " ms ");
                    }
                }

                yield return(new WaitForSeconds(0.2f));
            }

            for (int i = 0; i < AStarPerNFrames; i++)
            {
                FrontAxle.UpdateFriction();
                RearAxle.UpdateFriction();
                if (waypoints != null)
                {
                    ComputeSpeedAndSteer();
                    LookAhead();
                    Steer();
                    Move();
                }
                yield return(new WaitForSeconds(0.2f));
            }
        }
    }