I use this script, so when my player hits the grey square, another script from another object is activating. But it doesn’t work. The script that has to be activating is called ‘‘RandomSpawn’’. I deactivate it, because otherwise the script is activated when I start the game.
Also, it’s a bit unclear whether this script is attached to a player, or to some other object. If this script is attached to player. is RandomSpawn script also attached to player, because that is what your code looks like?
I made a new script and used a trigger instead of using collision, but it doesn’t seem to work. I attached this script to ‘‘GreySquare’’ and I did what you did ‘‘and be sure, both objects have collider 2D, and one have rigidbody 2d (you can add it to gray square and set it to kinematic)’’. Also my player really kind of lags right now.
Unity has a quick cheat sheet to check which objects produce a physical collision (colliders) or collision event (triggers) (scroll to the bottom). There’s also some great info about Static vs. Rigidbody/Rigidbody Kinematic Colliders Hope that helps!!!
put a bool on your spawn script & set it to false.
When your player hits the grey box access the spawn script & set the bool to true.
In the spawn script Update use an if statement so the spawn only works if the bool is true.
In that if statement, after the spawning has finished, set the bool back to false so it stops spawning.
Have you tried putting a breakpoint on the line that is setting the bool to true so you can check that it is finding it to update it? If it isn’t then there is an issue with the way you are trying to pass that across.
Also, why are you doing get component to set the bool on the spawner? If the spawn script is on the spawn point then the spawn script only néeds to have the bool without all the get component stuff.
If the spawn script is on the spawn object then it doesn’t need the get component to set the bool to false since the script is on that component.
A breakpoint is a debug tool. You set it on the line you think is causing the issue then run the game while using the debugger. It can be slow as it needs to load everything so give it a chance before you panic. The game will then run & when it goes to action the line/s with break points it will stop & flick to the code & by hovering the mouse over variables etc you can see the values before it runs, you then step into the code & see what the value is after the line runs. If your breakpoint is never called then you know your code has an issue as it isn’t actually processing your line.
I think once you turn a game object off it isn’t there any more to be found to turn back on. Research using break points & put one in at the collision & see what happens when it tries to find the component to turn it back on.
I actually think the issue is caused by enabling/disabling the object. Leave it always on & just use a bool on your spawner that is set to false, turns to true when the player hits the grey box & turns back to false after it has spawned however many items you want.