Unity Disparo desde Camara

En donde he puesto el Punto y la explosión seria el disparo, ahora mismo dispararíamos, pero no pasaría nada lo siguiente , cogeríamos nuestro disparo, y una vez creado lo incorporaríamos a la carpeta de prefab, con un Box Collider 2D el is Trigger activado, y con un Tag al que llamare dos, y con el script que dejare aquí abajo

 

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

public class Disparo : MonoBehaviour
{
void Start()
{

}

// Update is called once per frame
void Update()
{
Destroy(gameObject, 1f);

}
}

 

 

Con este Script el disparo, se eliminaría en un segundo, ahora vamos a nuestros enemigos y pondríamos el siguiente script

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

public class Enemigo : MonoBehaviour
{
// Start is called before the first frame update
void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.tag == «dos»)
{
Destroy(gameObject);
//or gameObject.SetActive(false);
}
}
}

Y ya podríamos probarlo

También te podría gustar...

1 respuesta

  1. Monte dice:

    For most recent news you have to visit world wide web and on internet
    I found this web site as a finest web page for most up-to-date updates.

Deja una respuesta

Tu dirección de correo electrónico no será publicada.