for second time why its not working i tried make the project again from zero 3 times im making top down game and i want when i touch the enemy destroy player
no errors just its not working
using UnityEngine;
public class touchscript : MonoBehaviour
{public float lifetime = 0;
public GameObject destroyer;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "player")
{
Destroy(destroyer, lifetime);
}
}
Time to start debugging. First of all, the collision documentation lists very clearly all the parts you need to have this working. Any one of those goes missing, none of it works. That’s software.
Beware there are two physics systems: is a 2D and 3D physics system. They are not aware of each other in any way. Pay close attention to what you are looking up.
By debugging you can find out exactly what your program is doing so you can fix it.
Use the above techniques to get the information you need in order to reason about what the problem is.
You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.
Once you understand what the problem is, you may begin to reason about a solution to the problem.
Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.