void Awake() { healthBarController = MonoBehaviour.FindObjectOfType(typeof(HealthBarController)) as HealthBarController; fuelBarController = MonoBehaviour.FindObjectOfType(typeof(FuelBarController)) as FuelBarController; if (debugPlayerController != null) { if (debugPlayerController is IPlayerControllerWithBars) { player = debugPlayerController as IPlayerControllerWithBars; player.HealthChanged += HealthChanged; player.FuelChanged += FuelChanged; } else { Debug.Log("Debug Player Controller needs to conform to IPlayerWithBars"); } return; } PlayerController controller = GetComponent <PlayerController>(); if (controller is IPlayerControllerWithBars) { player = (IPlayerControllerWithBars)controller; player.FuelChanged += FuelChanged; player.HealthChanged += FuelChanged; } else { Debug.LogError("Player Controller class needs to implement IPlayerWithBars" + "interface to communicate with health and fuel bars"); } }
protected virtual void Awake() { healthBarController = HealthBarController.HealthBarControllerWithName(NameOfHealthBar); fuelBarController = FuelBarController.FuelBarControllerWithName(NameOfFuelBar); }