- Home /
transforming a prefab randomly at runtime
I want to execute a script that will randomly display a prefab or object that will display randomly on the x and y axis ( this is a 2d platformer), but transforming at the same time. I currently have the object just transforming straight on the y axis using this transform.Translate(Vector3(0,0,speed) * Time.deltaTime);
i want this object to appear randomly in different positions. Sometimes high, sometimes low--but randomly and transforming using the above code.
Answer by Jake Haas · Jul 06, 2012 at 08:49 PM
You could always do something like this:
Pseudo Code:
if (Math.round(Math.randomRange(1, 10)) == 1) { // 10% chance instantiate prefab at new vector 3 (Math.randomRange(1, 10), Math.randomRange(1, 10), 0) }
Answer by v0nni · Jul 07, 2012 at 03:35 AM
i guess a more concise way for me to ask is how to I make this box move randomly up and downs similar to a vertical slider, but horizontal and going one direction
Answer by v0nni · Jul 07, 2012 at 03:30 AM
Actually, I am looking for a way to have an object transforming randomly. Thats the most simple way for me to explain.
'transform.Translate(Vector3(0,0,speed) * Time.deltaTime);'
would i just multiply this code by Random.Range?