Hi forum,
I am running in to an issue regarding moving ALL spawn objects only when button is pressed.
For example:
|_| <— spawn location
_ _ _ <— 3 locations 0
ABC
lets say we are spawning object “0”. and its spawns are called “0 (Clone)” by default i believe.
My c# script would be attached to the base object, so that its clones would also have the same code.
so at one point it would look like this:
00
000
000
I have 2 questions. When the button is pressed, bool pressed = true;
I want all of them to move to the left one spot at a time, when the button is pressed.
Button is created like this (if(Button.GUI(new Rect…)){script.pressed = true;}
After A, ill create a collusion box at which everything in it will get destroyed.
Question 1: when i run my script:
ran = true
inside FixedUpdate(){
if(pressed&ran)
Vector3 temp = this.transform.position;
temp.x = temp.x -10f;// space between B and C
this.transform.position=temp;
ran = false;
}
This will “move” every object 0 and 0(Clone) to the left. Which is half of what i wanted. I DO NOT want the object 0 to move, just all its clones. How do I implement that?
Later, I want to apply some physics to it, to see it actually move, instead of appearing on the screen.
Questions 2: The above script will allow me to run it once. I want to run it 3 more times to move it to the left of A, where it will then be destroyed.
how would i implement that? pressed is a global variable in a different script. So I just call script.methods() to call pressed, that is simple. But how can I run it 3 more times? Or n more times.
Since it is in a update function, I have to set something to false, or else it will just keep moving to the left non-stop, if i set the global variable to false on any one of those clones, then the clones after that clones would not move.
Anything comments helps!
Thanks All!