- Home /
Question by
nimmsnifo · Dec 20, 2016 at 02:27 PM ·
gameobjectcolliderdestroycollider2dcreate
Create Object when other Object hits ground.
I want to create a ball that falls on the ground and then turns in to another game object while being destroyed. So in my example it is a fruit that falls on the ground from which an tree is created.
Comment
Answer by GrKl · Dec 20, 2016 at 03:06 PM
If you are willing to add a character controller to your balls script:
CharacterController controller;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
if (controller.isGrounded)
{
Instantiate(prefab, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
Thank you very much What if the Object isn't controlled (like in a Simulation)?
if I recall correclty, Character controler does not need to be 'controlled' by the player. But if you have a lot of balls like that running at once, you could (and it actually might be better in any case) use OnCollisionEnter