- Home /
OnTriggerEnter not registering.
i have a script that sets a debug.log when it hits ANY trigger. it just doesn't make any sense because i put debug.logs everywhere and i got nothing. can you fellas look at his and tell me anything that might cause it not to register?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Wasp : MonoBehaviour {
public Transform Player;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.LookAt(Player);
transform.Translate(Vector3.forward * 1 / 24);
}
void OnTriggerEnter2D(Collider2D other)
{
Debug.Log("klajsdfhladsf");
if (other.CompareTag("weapon"))
{
Debug.Log("12312e1234");
Destroy(gameObject);
}
}
}
Answer by shadowpuppet · Apr 25, 2018 at 10:09 PM
if (other.CompareTag==("weapon"))
no, that's not the problem. i put a debug.log before the if statement and it still didn't show up. that means that it wont register no matter what the tag is
right. Well, for it not to be registering double check the gameObjects I guess. I don't do 2D so not sure what else it could be. The script - as I understand it - is on a wasp and it is facing the player and going at him and you want the wasp destroyed if he hits the players weapon or the weapon hits the wasp? $$anonymous$$ake sure the wasp has a trigger collider on it and that the weapon has a collider and, I think ,a rigidbody as well. I know I'd need one if it was 3D.
Follow this Question
Related Questions
In-Game Tutorial with special actions in special areas. (Shooter) 0 Answers
Slow collision triggers late 0 Answers
getComponent not working with Triggers? 1 Answer
Sound On Collision Not Working 3 Answers