OnTriggerExit problem

Its a short script so I pasted it here. So my Exit trigger won’t work nothing happens. The enter works no problem. Nothing gets destroyed or turned off except as you can see some game object components which does not effect this script or the game object its attached to or the colliding object.

ObjectA has box collider with trigger activated
ObjectB has box collider no trigger and a rigidbody.

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

public class ReleasedObjects : MonoBehaviour
{
public OVRGrabbable grabber;
public Transform releasePosition;
public string tagname;
private Transform positionRelease;
public GameObject parentObject;

void Start()
{
positionRelease = releasePosition;
}

void OnTriggerEnter(Collider replace)
{
if (replace.gameObject.tag == tagname)
{
gameObject.GetComponent().sheath = true;
gameObject.GetComponent().isKinematic = true;
gameObject.transform.parent = parentObject.transform;
transform.position = positionRelease.transform.position;
transform.rotation = positionRelease.transform.rotation;

}
}

void OnTriggerExit(Collider hand)
{
if (hand.gameObject.tag == tagname)
{
gameObject.GetComponent().inHand = true;
}
}

}

Check the first post in this forum for code formatting tips please!

To get more intel, put in some Debug.Log() statements here and there, make sure the functions you think should be called are even getting called.

I feel so foolish. I was calling for the component from the game object the scripts attached to. I needed the component from another game object. It works sorry and Thanks!

1 Like