I am new to Unity.
I added a script that works for new project. But it is executed only once when I attach it to an object under a folder for an existing project.
I looked document: Update is called if the MonoBehaviour is enabled. How can I enable MonoBehaviour?
You may think about oriented object programmation.
To enable/disable a gameObject/component in the Inspector, just tick / untick the box near the name of the gameObject or the component. Enabling / Disabling a gameObject enable/disabled all of his component (but not his children nor his parents).
To enable/disable a gameObject during play, use gameObject.active = true (or false).
To enable/disable a component during play, use (usually) component.enabled = true (or false).
Exemple : GetComponent(PlayerScript).enabled = false;
I took off the console collapse, I got many Update() executed. Thanks!
In my game, the player object should be on fire if it has been shot three times. So I need to detect the shoot times player object received at player side.
Rocket is the name of a script and PboatHits is a static variable.
However, at this time:
-program starts
-pirate shoots the first time, script at player side detected from static variable
-pirate shoots the 2nd, 3rd… times, Update() at player side is not executed and unable to detect number of shoots from the static variable
Thanks! Here is my two scripts. I did not get any error when I run it. It seems that once the enemy object started to fire the 2nd, 3rd…, the detecting script is not executed, and the global variable PirateBall.pirateHits could not be accessed. I do not know where is my problem.
Script attached to player side to detect how many hits it has received:
I assume the second script is named PirateBall ? Yes
Why a yield ? wait for one frame, something similar to: yield WaitForSeconds(5.0);- Why a transform.DetachChildren ? explorsion flame is a child of player object- Why are you looking for a ParticleEmitter in children ? same as above
The code works individually. But the first script (Update()) attached to player object is not executed after the enemy object fired the 2nd, 3rd … not sure the execution flow.