- Home /
How to pass variables to object's instance ?
I got a script that make mobs spawn over waves. The mobs shoot rockets at the player. I want rocket speed to increase over wave.
How can I do that ?
I have a variable waveNb in spawnerScript and I want to pass it to the script EnemyScript so he can pass it to MissileScript to make the rockets spawn with speed equals to waveNb + 25.
Answer by Mmmpies · Dec 27, 2014 at 09:05 AM
Hi, first off uploading relevant parts of your script will help people show how to fit in with your variables but it looks like you're new round here so that's just advice.
So by Wave you mean like a tower defense game where the the enemy gets ever more powerful?
if so then as you instantiate the enemy get the script component and pass it the waveNB value. Lets say you instantiate a prefab called Enemy
Enemy.GetComponent(EnemyScript).RocketPower = waveNB;
That assumes you have a public variable called RocketPower and your script attached Enemy is called EnemyScript.
Hope that makes sense.
I think that will help me cause that make sense. Ill try it to see if it work.
Your answer

Follow this Question
Related Questions
Access variable from multiple scripts 2 Answers
Need to use 2 different language scripts. 1 Answer
Static Variable Problem 1 Answer
Access a JavaScript variable from a C# script? 2 Answers
JavaScript controll var in C# 0 Answers