Exemplo n.º 1
0
        protected override void Awake()
        {
            //Calling BaseController's Awake function
            base.Awake();

            // Setting up the references.
            _carController = GetComponent <CarController>();
            _vehicleAI     = GetComponent <VehicleAI>();
            _playerHealth  = GetComponent <PlayerHealth>();

            //Acquiring Slider and Fuel image GameObjects if the player is not a bot
            if (!(_vehicleAI.Active))
            {
                FuelSlider = GameObject.Find("FuelSlider").GetComponent <Slider>();
                myFuel     = GameObject.Find("Fuel").GetComponent <Image>();
            }
            //myFuel = GetComponent<Image>();

            fuelFloat = 0.3f;

            // Set the initial fuel of the player.
            currentFuel = startingFuel;

            //Initializing the PlayerFuel's communicated velocity value
            playerFuelVelocity = 20f;
        }
        /// <summary>
        /// Physics initialization
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            //Setting up references
            _vehicleAI = GetComponent <VehicleAI>();

            // we set the physics gravity adapted to this game
            Physics.gravity = _gravity;

            // we change the center of mass below the vehicle to help with unity physics stability
            _rigidbody.centerOfMass += _centerOfMass;
        }
        // Use this for initialization
        protected override void Awake()
        {
            //Calling BaseController's Awake function
            base.Awake();

            //Setting up references
            _carController = GetComponent <CarController>();
            _vehicleAI     = GetComponent <VehicleAI>();
            _playerFuel    = GetComponent <PlayerFuel>();

            //Acquiring Slider and Health image GameObjects if the player is not a bot
            if (!(_vehicleAI.Active))
            {
                HealthSlider = GameObject.Find("HealthSlider").GetComponent <Slider>();
                myHealth     = GameObject.Find("Health").GetComponent <Image>();
            }

            //Set the initial health of the player
            currentHealth = startingHealth;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes the players of the race. Instantiation of gameobjects in single / local mode
        /// </summary>
        protected virtual void InitPlayers()
        {
            if (_isNetworkMode)
            {
                Debug.LogError("This function should not be called in network mode");
                return;
            }

            // List of car controllers transforms. Used by camera controller target
            List <Transform> cameraHumanTargets = new List <Transform>();
            List <Transform> cameraBotsTargets  = new List <Transform>();

            // start position for current instantiated player
            int _currentStartPosition = 0;

            // we iterate through each lobby player with bots first
            List <ILobbyPlayerInfo> playersAtStart;


            // we order players list with bots first
            if (BotsFirstInStartingLine)
            {
                playersAtStart =
                    LocalLobbyManager.Instance.Players()
                    .Select(x => x.Value)
                    .OrderByDescending(x => x.IsBot)
                    .ToList();
            }
            else
            {
                playersAtStart = new List <ILobbyPlayerInfo>(LocalLobbyManager.Instance.Players().Values);
            }

            foreach (ILobbyPlayerInfo item in playersAtStart)
            {
                GameObject prefab;

                if (item.VehicleSelectedIndex >= 0)
                {
                    prefab = LocalLobbyManager.Instance.AvailableVehiclesPrefabs[item.VehicleSelectedIndex];
                }
                else
                {
                    // test mode, we find the prefab with a resources load
                    prefab = Resources.Load("vehicles/" + item.VehicleName) as GameObject;
                }

                // we first instantiate car for this player.
                // the car name value is used to load the prefab from Resources/Vehicles folder.
                GameObject newPlayer = Instantiate(
                    prefab,
                    StartPositions[_currentStartPosition],
                    Quaternion.Euler(new Vector3(0, StartAngleDegree, 0))
                    ) as GameObject;

                // we add this new object to the list of players
                BaseController car = newPlayer.GetComponent <BaseController>();
                _players[item.Position] = car;

                car.name = item.Name;

                // We initialize AI component
                VehicleAI ai = newPlayer.GetComponent <VehicleAI>();
                if (ai != null)
                {
                    ai.Active = item.IsBot;
                }

                // we add this car gameobject to the camera targets
                if (item.IsBot)
                {
                    cameraBotsTargets.Add(newPlayer.transform);
                }
                else
                {
                    cameraHumanTargets.Add(newPlayer.transform);
                }

                // we go to next start position
                _currentStartPosition++;
            }

            // we add the list of players to the cameras
            List <CameraController> availableCam = new List <CameraController>();

            foreach (var c in CameraControllers)
            {
                c.gameObject.SetActive(false);

                // This camera can't be used in local multi
                if (cameraHumanTargets.Count() > 1 && c.IsSinglePlayerCamera)
                {
                    break;
                }

                c.BotPlayers   = cameraBotsTargets.ToArray();
                c.HumanPlayers = cameraHumanTargets.ToArray();
                availableCam.Add(c);
            }

            _cameraControllersAvailable = availableCam.ToArray();

            if (DynamicCameras && _cameraControllersAvailable.Length == 0)
            {
                Debug.LogError("No camera available found. Please ensure at least one camera is configurated in RaceManager inspector.");
                return;
            }
            else
            {
                if (DynamicCameras)
                {
                    // By default, we active first camera
                    ChangeActiveCameraController(0);
                }
            }
        }