So I have been trying to make a script that when it’s been executed it will change the properties of another script’s variable. However, when I try to do this when unity gets to the part of the script with the get component in it, it will just not execute the rest of the code. This is problematic and I am in need of help. Thank you!
Problematic Code Chunk:
GameObject Score2;
print ("Where unity gets to");
GetComponent<ScoreCounter>().counter += 1;
print ("Doesn't execute anything past here");
I am not familiar with C# quite yet, I have been learning for unity so I still need help. Thanks again!
Have you checked the console for errors? It’s most likely getting an exception.
It doesn’t print any errors, I put the print statements there to try and see if it was even reading the code. It just prints “Where unity gets to” and that’s it, it doesn’t do the rest of the code
I don’t know of any way for execution of code to just end like that without an exception being thrown. I think that means one of two possibilities:
- Your console may be not showing error-type messages. (Top-right of the console window, you should have the 3 buttons (thought bubble, yield sign, stop sign) - make sure all 3 are enabled)
- The exception is being thrown somewhere that’s not being detected by Unity (i.e. outside of the normal execution loop). Could you provide more context to your code snippet?
1 Like