how do i make this work for 3d objects
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
public GameObject dylan;
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "dangerousnpc")
Destroy(dylan);
}
}`
OnTriggerEnter()
is the rough equivalent to the OnTriggerEnter2D()
you reference above. See the docs for how it differs in terms of argument type.
Of course, no script would ever work unless you obey basic script naming rules. Do you really have this class and its filename called NewBehaviourScript
and NewBehaviourScript.cs
?
I tried using ontrigger enter but it didn’t autocorrect in when i tried just typing it in there was an error
I have the tag on the gameobject with the collider and have the gameobject i want deleted dragged into the public class I’m not sure why the code isn’t working do you know of a way to write this code for my scenario any advice would be appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EvilNpc : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
public GameObject Player;
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "dangerousnpc")
Destroy(Player);
}
}
I’ve been playing around with ontriggerenter.other and it doesn’t quite work the and the doc i found on it was sort of confusing
Sounds like you wrote a bug… and that means… time to start debugging!
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.