- Home /
Random instantiate script
I want a script that some ball going up the screen randomly and we can click on it to have some point ... I don't know how to do this script.
Thanks for your help
Answer by zmar0519 · Mar 10, 2011 at 01:57 AM
Your question wasn't quite clear, but I think that you want a ball to move up the screen but start at a random point on an axis?.
If so, then try this script:
var fireRate : float;
var ball prefab : GameObject;
private var lastShot : float = 0;
function Update()
{
if(Time.time > lastShot) {
var go : GameObject = Instantiate(ballPrefab, transform.position, transform.rotation);
lastShot = Time.time + fireRate;
}
}
Then just add a constant force to the ball, and a simple ping pong movement(via animation) to the empty game object the above script is attached to.
Your answer
Follow this Question
Related Questions
instantiate a prefab from array and then changing it 1 Answer
How can I Instantiate an Object from a Randomly Selected Index in an Array of Game Objects? 1 Answer
For Loop isn't working properly! 1 Answer
Creating a light in game C# 1 Answer
Random.value sometimes doesn't instantiate my prefab(pic included) 1 Answer