Beispiel #1
0
        /// <summary>
        /// Initializes components
        /// </summary>
        protected virtual void Start()
        {
            _playerHealth  = GetComponent <PlayerHealth>();
            _playerFuel    = GetComponent <PlayerFuel>();
            _carController = GetComponent <CarController>();

            myAnim = GetComponent <Animation>();

            _soundManager = FindObjectOfType <SoundManager>();

            _leftSmokeShape  = SmokeLeft.shape;
            _rightSmokeShape = SmokeRight.shape;
            _smokeAngle      = SmokeLeft.shape.angle;

            _smokeLeftEmission  = SmokeLeft.emission;
            _smokeRightEmission = SmokeRight.emission;
            _rocksLeftEmission  = RocksLeft.emission;
            _rocksRightEmission = RocksRight.emission;

            _smokeLeftEmission.enabled  = true;
            _smokeRightEmission.enabled = true;
            _rocksLeftEmission.enabled  = false;
            _rocksRightEmission.enabled = false;

            _skidmarksLeft = Instantiate(
                Resources.Load <GameObject>("Particles/Skidmarks"),
                SmokeLeft.transform.position, SmokeLeft.transform.rotation) as GameObject;

            _skidmarksRight = Instantiate(
                Resources.Load <GameObject>("Particles/Skidmarks"),
                SmokeRight.transform.position, SmokeLeft.transform.rotation) as GameObject;

            _skidmarksLeft.transform.parent  = SmokeLeft.transform;
            _skidmarksRight.transform.parent = SmokeRight.transform;

            if (EngineSound != null)
            {
                _soundManager = FindObjectOfType <SoundManager>();
                if (_soundManager != null)
                {
                    _engineSound = _soundManager.PlayLoop(EngineSound, transform.position);

                    if (_engineSound != null)
                    {
                        _engineSoundPitch   = _engineSound.pitch;
                        _engineSound.volume = 0;
                    }
                }
            }
        }
        // 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;
        }