I'm creating a game in Unity 3D for android phones. Currently I'm using sphere as my main object. I just want to ask if how I could create another sphere in the scene once first ball is thrown and disappear. It just like another ball to shoot in basketball game.It will continue to have a sphere/ball until time is already zero. Thank you.
Have a look at Prefabs . You just need to create a prefab out of your GameObject and can then create new instances using the Instantiate
var sphere : GameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
CreatePrimitive Documentation
If you don't want the basic sphere you'll have to Instantiate a prefab like Kay says in his Answer.
var prefab : Transform;
function OnTriggerEnter () {
Instantiate (prefab);
}
You need to Instantiate the ball when you need a new ball. Following sample code might help you:
public GameObject ball;
bool isBallThrown; //trigger that to true when ball is to be thrown
void Update(){
if(isBallThrown){
Instantiate(ball,new Vector3(2,3,0),Quaternion.identity));
isBallThrown=false;
}
}
Attach the sphere to ball GameObject..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.