I’m new by the way. I’m trying to add health to a cube and click the play button in unity and it says the code is filled with errors. i’m using the code from a video
Oh and Now i’ve added this code it supposed to decrease health from the cube i guess every few seconds or something but when i click play it doesn’t really do anything. in the video that i’m watching the health drops like a ever few but for me it doesn’t even display that the health is dropping in the console This is the code now.
Your code says “when the scene starts, subtract 10 from my health property.” I bet that it does do that. But apparently that’s not what you want.
So, you can either go back and compare your code to the video you’re watching more carefully, or describe more precisely what you want and we’ll try to help.
But here’s a hint: if you want stuff to happen on every frame, rather than just at the start, then you need to use the Update method (rather than the Start or Awake method).
okay thank you here are my questions (sorry im a bigenner and i learn in weird ways xD)
1: in the video i didn’t see the uploader put the word ‘Update in the code’ and it still updated for him why is that?
2: Since the health is 10 and i’m subtracting 10 is that why the consoles not updating because its basicly starting and 10 and when i play the scene it auto subtracts 10 so theres no reason for it to update?
3:I’m trying to have the console update each time the player/cube losses health
4: i’m out of questions lol
First of all, I now have a dedicated support forum for questions regarding my videos. This is an older video, but I’ll still help you on ForgeUnity.com.
For now, though, you’re subtracting the amount from your health, but you’re never writing that to the console. If you watch the video, it writes to the console because I use Debug.Log to do so.
Just make sure you watch the video again and pay close attention. They’re older videos, but I’m pretty sure I didn’t leave out absolutely everything. lol
Instructions run in the order they’re in. So if you log first than then subtract 10, it will show the value from before you subtracted 10. If you subtract 10 first then log, it will show the value after 10 has been subtracted.
Reading up on some basics of how C# works first will make the tutorials a lot easier to understand.