Question by
Lolypop79 · Jul 13, 2020 at 08:11 PM ·
unity 5instantiate3ddestroy
Destroy an INDIVIDUAL instantiated object
Hello! I'm having this problem with my game. When I spawn a spit, I want to to destroy the spawned object after 2 seconds. But this doesn't happen. Once 2 seconds are up, no more spits spawn. Spit is something that the player doesn't want to touch and it spawns on the ground. Here are 2 scripts, the top is my bullet script. And the second is the spit script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletMovement : MonoBehaviour
{
// Start is called before the first frame update
public int bulletSpeed = 5;
// Update is called once per frame
void Update()
{
GetComponent<Rigidbody>().AddRelativeForce(Vector3.forward * bulletSpeed, ForceMode.Impulse);
Destroy(this.gameObject, 2.0f);
}
void OnCollisionEnter(Collision collision)
{
Destroy(this.gameObject);
}
}
and
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spit : MonoBehaviour
{
void Update()
{
Destroy(this.gameObject, 2.0f);
}
Please help! I don't see anything wrong...
Comment