- Home /
C# Instant OnTriggerEnter Detection
Is there a way to make an OnTriggerEnter detect gameobjects as soon as they are in the trigger collider? I have a gameobject that upon start has it's position equal the trigger collider's position. But the script for the trigger collider never executes. Any idea why the OnTriggerEnter function never executes? I need to use OnTriggerEnter so other gameobjects can pass through the collider.
using UnityEngine;
using System.Collections;
public class OnTriggerTransformPositionScript : MonoBehaviour {
public GameObject OnTriggerGameobject;
// Use this for initialization
void Start () {
gameObject.transform.position = OnTriggerGameobject.transform.position;
}
}
using UnityEngine;
using System.Collections;
public class OnTriggerScript : MonoBehaviour {
void OnTriggerEnter (Collider cols) {
Debug.Log("A Gameobject is within Trigger Collider");
}
}
check that there is a rigidbody involved. Ensure that one of them is a trigger.
Yep that fixed it. Could you please turn your comment into an answer so I can mark this as solved?
Your answer
![](https://koobas.hobune.stream/wayback/20220613155006im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
C# Instant Teleport Script 1 Answer
C# Input.GetKey("Tab") Double Tap 1 Answer
Player lives script help 1 Answer
C# -- Build character unit from script 1 Answer
InvokeRepeating repeating too often with OnTriggerEnter 1 Answer