Unity - How to trigger animation on collision

Поділитися
Вставка
  • Опубліковано 23 січ 2025

КОМЕНТАРІ • 22

  • @piouslake2816
    @piouslake2816 6 місяців тому

    You're a lifesaver.

  • @TJS123
    @TJS123 2 роки тому +34

    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();
    }
    }
    }

    • @crleo8709
      @crleo8709 2 роки тому +1

      thank you for the script, it's very helpful!!!

    • @universedavestudiotv4834
      @universedavestudiotv4834 2 роки тому +1

      thank you!

    • @nickram2009
      @nickram2009 2 роки тому +7

      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)

    • @ultimav3868
      @ultimav3868 2 роки тому

      Thank you bro

    • @MsRaskauskas
      @MsRaskauskas Рік тому +1

      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?

  • @TS-rp7dz
    @TS-rp7dz 2 роки тому +6

    Please can you give us the script

  • @extravirginoliveoil2
    @extravirginoliveoil2 2 роки тому +9

    correction: tutorial on how to move object position on animation

  • @MysteryUnclear
    @MysteryUnclear 2 роки тому

    plz man tell me bro haw can i just make a ui button witch rotate my car backward and forward

  • @TJS123
    @TJS123 2 роки тому +1

    was very useful but providing a script wouldve been helpful

  • @cybersoff149
    @cybersoff149 2 роки тому

    Cssn you make a video of how to do this in unity 3d?

  • @botaniccanon1596
    @botaniccanon1596 Рік тому

    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

  • @radhikajain15
    @radhikajain15 Рік тому

    Very helpful, Thank you!!

  • @leoisforevercool
    @leoisforevercool 3 роки тому

    Thanks!

  • @infpya
    @infpya Рік тому +1

    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();
    }
    }
    }

  • @eduardomoroian4618
    @eduardomoroian4618 2 роки тому +5

    Without sharing the script with us this video is useless