Unity: Triggering Parent Animation using OnTriggerEnter2D

46 views Asked by At

this is my first time of positing on any forum, so here goes...

I am making my own Unity 2D game. However, I am really stumped with triggering an animation and I have been trying for a long time to try and resolve... if you're the person that can help then I would really appreciate it.

1 - I have a 2D collider on my aircraft carrier. See image 'Landing Carrier'. 2 - I have a script on this:

public class AirCraftCarrier : MonoBehaviour
{
Player player;
MoveLevel moveLevel;

void Start()
{
    player = FindObjectOfType<Player>();
    //moveLevel = FindObjectOfType<MoveLevel>();
}

void OnTriggerEnter2D(Collider2D other)
{
    Debug.Log("Collision");
    player.LandJet();
}
}

3 - I have a player, which has a script and public method to either trigger my animation or set the bool to activate it in code:

public void LandJet()
{
    animator.SetBool("LandShip", true);
    //animator.SetTrigger("LandShip");
}

4 - The animator is attached to a parent object on the player. The Player script is attached to the child. Therefore, my logic is to get a reference like so, on my player script. public Animator animator;

void Awake()
{
    animator = GetComponentInParent<Animator>();
}

Whatever I try to do it will NOT fire that damn animation. What am I doing wrong? It will print to the console, it will destroy the object if I want it... but no animation triggers.

To confirm, I have added the landing carrier's Box Collider 2D as the trigger. I've experimented with swapping these around but no joy. See images. I would be really grateful for any advice.

Thanks in advance.

enter image description here

Other things tried: I have tried swapping the triggers. I tried using animation .SetTrigger I have tried using other game objects to trigger the animation. I've rewritten the script a few times as well and searched online for a solution.

See screen shot of animation settings.

Not sure what other screen shots to include.

Maybe it is helpful to show the game object where the script is, see attached. enter image description here

enter image description here

1

There are 1 answers

0
Myerpheus On

It seems that this was in fact working, but Unity wasn't taking the updates. Upon restart the problem is resolved.