Question by
adieraditz · Nov 18, 2019 at 11:55 PM ·
gameobjecttransformdestroyeffecttimed
how to gameobject timed destroy with effect
hello, b4 i asking sorry for my bad english
i already know how to bullet explode after impact and i know to how to destroy gameobject in certain time
but in my case how to destroy bullet in certain time (if i missed the shoot) and exploded, just like when my bullet got collided?
i already search but no hope thanks
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bullet : MonoBehaviour
{
public Collider2D player;
public GameObject hiteffect;
public float lifetime = 1f;
void start()
{
if(lifetime <= 0)
{
GameObject effect = Instantiate(hiteffect, transform.position, Quaternion.identity);
Destroy(effect, 1f);
Destroy(gameObject);
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
Physics2D.IgnoreLayerCollision(10, 11);
GameObject effect = Instantiate(hiteffect, transform.position, Quaternion.identity);
Destroy(effect, 1f);
Destroy(gameObject);
}
}
Comment
Your answer
Follow this Question
Related Questions
Why does destroying a gameObject influence its former children? 1 Answer
Canon Ball shooting with Instiate 1 Answer
If you want to destroy the game object, please call 'Destroy' on the game object instead. 1 Answer
this.GetComponent() won't return gameObject? How to get it without using this.gameObject? 3 Answers