Fox jump trigger not triggering

so im using Unity 2017.2.0f3 since i got license for plus, but my quistion is if there is changes for the code in 2017 to get animator.SetTrigger? my fox does not jump when it collides with the stone. nor is it attacking when it colide with other objects
my stone got the collider2D, and Stone and Defender Script. fox got RigidBody2D, the scripts and collider2D
This is how my code looks:

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

[RequireComponent (typeof (Attacker))]
public class Fox : MonoBehaviour {

    private Animator anim;
    private Attacker attacker;

	// Use this for initialization
	void Start () {
        anim = GetComponent<Animator>();
        attacker = GetComponent<Attacker>();
	// Update is called once per frame
	void Update () {

    void OnCollisionEnter2D(Collision2D collider)

        GameObject obj = collider.gameObject;
        // Leave the method if not colliding with defender
        if (!obj.GetComponent<Defender>())

        if (obj.GetComponent<Stone>())
            anim.SetTrigger("Jump trigger");
        } else
            anim.SetBool("isAttacking", true);
            Debug.Log("Fox collided with" + collider);

Hi Alex,

I noticed that your calling “Jump trigger” (lower-case t), can you check that this is exactly how the trigger is named within your animator.

If it is, the next thing I would probably start with is placing a

Debug.Log("A collision just occurred with : " +;

at the very top of the OnCollisionEnter2D method, before the rest of your code. Then just pop a stone and a fox in the scene and make them collide - if you don’t see the above output, you know that the collisions aren’t being detected.

Let us know what you spot. :slight_smile:

Updated Wed Nov 22 2017 18:06

Just noticed that you have the Debug.Log at the bottom, maybe just drag that up to the very top, so that it is the first thing that is called.

See also;

1 Like

it seems Fox.cs dont register a collision with the stone, but the attcaker.cs does.

Do you have the attacker.cs script added as a component of the Fox prefab?

this is how the fox prefab looks like.

and code aded here:

1 Like

Trying changing your OnCollisionEnter2D, OnTriggerEnter2D, e.g.;

private void OnTriggerEnter2D(Collider2D collider)

Note - you have the Is Trigger ticked in the Inspector for the Fox.

OnTriggerEnter2D did the trick. Tried to untick the Is Trigger, but it had no effect, so i gues i have to stick with OnTriggerEnter2D.

Thank you very much for the help :slight_smile:

1 Like

You’re more than welcome Alex - glad you can move forwards :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms