ProjectAstero 05- Destroyable Object

Hi,

Today I will show you how to create destroyable objects for our game,

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HostileObject : MonoBehaviour
{

    private void OnTriggerEnter2D(Collider2D collision) //UPDATE
    {
        //TODO:: Destroy Animation
        //TODO:: AddScore
        Destroy(this.gameObject);
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Projectile : MonoBehaviour
{
    public float ProjectileSpeed;
    private Rigidbody2D rb2d;
    [SerializeField]
    float TimeToDestroAfterInstantiation; // UPDATE
    private void Start()
    {
        rb2d = GetComponent<Rigidbody2D>();
        rb2d.velocity =transform.up* ProjectileSpeed;

        Destroy(this.gameObject, TimeToDestroAfterInstantiation); //UPDATE Destroy(this.gameObject, 2);
    }

    private void OnTriggerEnter2D(Collider2D collision) //UPDATE
    {
        //TODO:: Destroy Animation
        Destroy(this.gameObject);
    }


}

Leave a Reply

Your email address will not be published. Required fields are marked *