I’m relatively new to Unity, and my shooting script is not working. I’m planning to shoot (instantiate a sphere) then destroy the sphere 5 seconds later. Without the following script, I can shoot, but the spheres will stay on screen. With it, or the Destroy(gameObject, float) on the instantiated sphere, the sphere is destroyed as soon as it is instantiated. Please help.
Here’s the code:
if(Input.GetButtonDown(“Shoot1”))
{
var OffsetCenter = transform.position + center;
var instancesphere = Instantiate(sphere, OffsetCenter, transform.rotation);
instancesphere.rigidbody.AddForce(transform.forward * sphereforce);
Destroy(instancesphere.gameObject, 5);
}