- Home /
assign n gameobject and change value?
okay, those screenshots may help you to understand what I mean. say, I have four gameobject(particly system) which shows my spaceship thruster. I want to assign them into one script as element0, ~ , element3. when I press forward key, then change the start size to 0.7, like I used booster or sth. I'm pretty newb to unity and don't know what I need to do.
assign number of gameobjects into one script(they are all particle system).
when I press forward(<-I know how to do this) then the script changes the start size to [numberIwant].
these are what I want to achieve. I don't know: how to assign gameobject as var(am I correct?) and change its var. please help me :)
Answer by UnbreakableOne · Jan 06, 2014 at 01:19 PM
To reply with your questions:
Write a script and public a field to your particle system type, then drag and drop the particle to that field in editor. Then in your "press key", use that field to change variable to what you want. Let me write a pseudo code for you:
public ParticleSystem ParticleSystem_Reference_1;
void Update()
{
if(Input.GetButtonDown("[F]"))
{
ParticleSystem_Reference_1.StartSize = 0.9 //whatever you want
}
}
I'm new to Unity as well, so this might just get you started.
aaaaah thanks! that simple lines are what I needed! thank you very much sir!
Your answer
![](https://koobas.hobune.stream/wayback/20220613125658im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Beginner: assigning texture to part of GameObject 1 Answer
Assigning variables in inspector 1 Answer
Disable/Enable Script or Add/Remove? 1 Answer
static var for one object. 2 Answers
How to change variables on a new gameobject's script 1 Answer