Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialkembaa
3,413 PointsplayerHealth.alive not working. alive does not have a definition
if(playerHealth.alive == false) { //...end the game EndGame(); //... increment a timer to count up to restarting restartTimer = restartTimer + Time.deltaTime; if (restartTimer >= restartDelay) { // ...then reload the currently loaded level. SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } } it says alive does not have a definition any ideas on where I could find this?
1 Answer
Steven Clement
11,473 PointsCheck your variables at the top of the class (assuming you are in GameState.cs). Make sure you have:
private PlayerHealth playerHealth;
Then look at your void Start() function. Make sure you have:
playerHealth = player.GetComponent <PlayerHealth>();
Finally make sure you have a script called PlayerHealth.cs
Case matters so if you named your script playerHealth instead of PlayerHealth you will get the error you are seeing.