Hi, I'm creating a simple game, and I can't kill cloned object with rigidbody component. Script just deletes rigidbody component.
Here's the code:
public class ShooterProt : MonoBehaviour
{
public Rigidbody projectile;
public Transform BarrelEnd;
[SerializeField]protected float ShootForce = 2000f;
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Shoot();
}
}
void Shoot() {
Rigidbody clone;
clone = Instantiate(projectile, BarrelEnd.position, BarrelEnd.rotation) as Rigidbody;
clone.AddForce(BarrelEnd.forward * ShootForce);
Object.Destroy(clone, 1f);
}
}
↧