- Home /
The question is answered, right answer was accepted
If statement failing OnTriggerEnter
Sorry to bother everyone here, but I have reached a dead end in my brain.. documentation has not aided me in my search, and all examples/threads I have run across have left me without resolution.
I have Trigger collider on a child object trying to to pass code to the parent object. I have confirmed that if I remove the "if tag =" from the scenario the code works as it is intended. However if I add the if condition in place, it does not.
Code snippet for your consideration and highly appreciated assistance if given.
Additional information: Yes I have confirmed the tag on the "Player" object, and the player object does have a Rigidbody (Kinematic) associated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraSpot : MonoBehaviour
{
private SecurityCamAction parent;
private void Start()
{
parent = transform.parent.GetComponent<SecurityCamAction>();
}
public void OnTriggerEnter(Collider other)
{
// if I elminate the if statement below, the collision is recognized.
if(other.tag == "Player")
{
Debug.Log("I see something"); //this fails to print to console.
parent.OnChildTriggerEnter();
}
}
}
Thank you for any assistance you could provide..
try if(other.collider.gameObject.tag) and make sure the GO has a rigidbody and a collider
Thank you Llama... I failed to recognize that the character selection spawner was instantiating an older prefab that did not have the collider associated.
I think I need to put this project down for a day or two and recharge.
Follow this Question
Related Questions
If I deactivate the collider and then reactivate it, the trigger no longer works? 1 Answer
Multiple triggers on one object still a no? 1 Answer
c# trigger collider makes character controller misbehave. 1 Answer
C#: Climb ledge while inside collider 1 Answer
How to Destroy items in Match 3. 2 Answers