Пример #1
0
    // We use Awake() rather than Start() so that the render texture resources are available
    // early on when other objects are Start()'ed
    void Awake()
    {
        _light = GetComponentInChildren <Light>();

        for (int i = 0; i < PlayerManager.MaxNumPlayers; i++)
        {
            _renderTexture[i] = new RenderTexture(512, 512, 24, RenderTextureFormat.ARGB32);
            _renderTexture[i].autoGenerateMips = false;
            _renderTexture[i].name             = "PlayerSelectRT" + i;
            _renderTexture[i].Create();
        }

        // Instatiate one of each car for the car selection screens
        int targetLayer = LayerMask.NameToLayer("3DUI");

        for (int i = 0; i < CarLibrary.NumCars; i++)
        {
            GameObject car = carLibrary.InstantiateCar(i);
            SetObjectLayer(car, targetLayer);
            //car.layer = targetLayer;
            //for (int j = 0; j < car.transform.childCount; j++)
            //{
            //    car.transform.GetChild(j).gameObject.layer = targetLayer;
            //}
            car.transform.rotation = Locator.transform.rotation;
            car.SetActive(false);
            _carModels.Add(car);
        }

        RenderCamera.enabled = false; // We want to manually render
    }
Пример #2
0
    public override void Begin()
    {
        CarLibrary    carLibrary    = GetCarLibrary();
        PlayerManager playerManager = GetPlayerManager();

        _raceState  = RaceState.Countdown;
        _stateTimer = CountdownTime;

        // Grab child objects and setup (assumptions are made here!)

        for (int i = 0; i < PlayerManager.MaxNumPlayers; i++)
        {
            GameObject raceLocatorStart = GameObject.Find(RaceStartLocatorName + (i + 1));
            GameObject raceLocatorEnd   = GameObject.Find(RaceEndLocatorName + (i + 1));
            GameObject car = carLibrary.InstantiateCar(playerManager.GetPlayerSelectedCar(i));

            _racePositionStart[i] = raceLocatorStart.transform.position;
            _racePositionEnd[i]   = raceLocatorEnd.transform.position;

            car.transform.position = _racePositionStart[i];
            car.transform.rotation = raceLocatorStart.transform.rotation;
            _cars.Add(car);

            GameObject carMarker = Instantiate(CarMarkerPrefab, car.transform.position, car.transform.rotation);
            carMarker.transform.localRotation = Quaternion.AngleAxis(90, Vector3.up);
            carMarker.GetComponentInChildren <Text>().text = (i + 1).ToString();
            _carMarkers.Add(carMarker);

            if (playerManager.IsPlayerAI(i))
            {
                _AITapsPerSecond[i]          = Random.Range(5.5f, 9.5f);
                _AITimeUntilChangeTapRate[i] = Random.Range(2.0f, 4.0f);
            }

            _raceProgress[i]         = 0.0f;
            _raceProgressSmoothed[i] = 0.0f;
        }

        GameObject UI = GameObject.Find(RaceUIName);

        Text[] texts = UI.GetComponentsInChildren <Text>();
        for (int i = 0; i < texts.Length; i++)
        {
            if (texts[i].name == "Countdown")
            {
                _countdownText = texts[i];
            }
            if (texts[i].name == "Celebration")
            {
                _celebrationText = texts[i];
            }
        }

        _countdownText.enabled   = true;
        _celebrationText.enabled = false;

        _camera                 = GetComponentInChildren <Camera>();
        _cameraStart            = GameObject.Find(CameraStartLocatorName).transform;
        _cameraEnd              = GameObject.Find(CameraEndLocatorName).transform;
        _cameraProgressSmoothed = 0.0f;
    }