Script using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; public class MyEventTriggerOnEnter : MonoBehaviour { [Header("Custom Event")] public UnityEvent myEvents; private void OnTriggerEnter(Collider other) { if (myEvents == null) { print("myEventTriggerOnEnter was triggered but myEvents was null"); } else { print("myEventTriggerOnEnter Activated. Triggering" + myEvents); myEvents.Invoke(); } } }
For those who are wondering why this does not work for 2D game insted: of private void OnTriggerEnter(Collider other) use: private void OnTriggerEnter2D(Collider2D collision) Hope i saved you some nerves and time)
Thank you for this but it is not working for me. I am new at this but trying to help a student who wants to trigger an animation in 3D such as this. I am getting the error message that the script is not able to be applied and there are no public variables showing in the inspector to add the trigger etc. Do I have to change the code to fit my assets?
Thanks ever so much for your video content. I appreciate it!!! if you have some time, can you help me with how to make an object collide with another object three times, then play an animation? I am a beginner in coding so can you script it out for me to understand. Thanks
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; public class myEventTriggerOnEnter: MonoBehaviour [Header('CustomEvent')] { public UnityEvent myEvents; private void OnTriggerEnter2D(Collider2D other) { if (myEvents==null) { print("myEventTriggerOnEnter was triggered but myEvents was null."); } else { print("myEventTriggerOnEnter Activated. Triggering"+myEvents); myEvents.Invoke(); } } }
You're a lifesaver.
Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class MyEventTriggerOnEnter : MonoBehaviour
{
[Header("Custom Event")]
public UnityEvent myEvents;
private void OnTriggerEnter(Collider other)
{
if (myEvents == null)
{
print("myEventTriggerOnEnter was triggered but myEvents was null");
}
else
{
print("myEventTriggerOnEnter Activated. Triggering" + myEvents);
myEvents.Invoke();
}
}
}
thank you for the script, it's very helpful!!!
thank you!
For those who are wondering why this does not work for 2D game
insted: of private void OnTriggerEnter(Collider other)
use: private void OnTriggerEnter2D(Collider2D collision)
Hope i saved you some nerves and time)
Thank you bro
Thank you for this but it is not working for me. I am new at this but trying to help a student who wants to trigger an animation in 3D such as this. I am getting the error message that the script is not able to be applied and there are no public variables showing in the inspector to add the trigger etc. Do I have to change the code to fit my assets?
Please can you give us the script
correction: tutorial on how to move object position on animation
plz man tell me bro haw can i just make a ui button witch rotate my car backward and forward
was very useful but providing a script wouldve been helpful
Cssn you make a video of how to do this in unity 3d?
Thanks ever so much for your video content. I appreciate it!!! if you have some time, can you help me with how to make an object collide with another object three times, then play an animation? I am a beginner in coding so can you script it out for me to understand. Thanks
Very helpful, Thank you!!
Thanks!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class myEventTriggerOnEnter: MonoBehaviour
[Header('CustomEvent')]
{
public UnityEvent myEvents;
private void OnTriggerEnter2D(Collider2D other)
{
if (myEvents==null)
{
print("myEventTriggerOnEnter was triggered but myEvents was null.");
}
else
{
print("myEventTriggerOnEnter Activated. Triggering"+myEvents);
myEvents.Invoke();
}
}
}
Without sharing the script with us this video is useless