- Home /
Question by
levjackie14 · Jan 24, 2016 at 04:05 PM ·
unity 5scripting beginnernoob
Setting GameObject in a script.
I have a projectile set as a game object, a 2d sprite prefab, I declared is at a public GameObject and was able to drag a prefab to make it work, no problem. In special circumstances I want it to be another prefab. How do I set the game object: Projectile to the special prefab.
thank you for all your help.
switch (Convert.ToChar (valueOfTokens [1])) {
case '+':
genApples (float.Parse(numbers [temp]));
break;
case '-':
//set GameObject to new prefab and generate some apples.
Projectile = GameObject.Find("Projectile_Prefab 1") as GameObject;
genApples (float.Parse(numbers [temp]));
break;
default:
genApples (float.Parse(numbers [temp]));
break;
}
}
void genApples(float apples){
while (apples != 0) { //drop some apples
GameObject Goz = Instantiate (Projectile, ShootPt.transform.position, ShootPt.transform.rotation) as GameObject;
apples--;
}
Comment
Your answer
Follow this Question
Related Questions
Change the FOV from "60" to "90" smoothly when pressing "W" (C#, first time posting, beginner) 2 Answers
Instantiate an object each time in less time 2 Answers
How to detect which how many of a type a variable a script has 1 Answer
Game is not restarting after gameOver=true 1 Answer
I'm trying to allow my character to only jump when grounded 1 Answer