Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

OnCollisionEnter2D not working

Discussion in 'General Discussion' started by floevomojobo, Nov 22, 2014.

  1. floevomojobo

    floevomojobo

    Joined:
    Nov 22, 2014
    Posts:
    1
    Hey guys,

    Still very new to Unity and I've been following this tutorial on youtube called "Clonybird" when I ran across a problem. So basically my game is 2D.

    What I have so far is a player sprite with two animations and a ground sprite. Below are some screenshots that will help assess the situation.

    Here's my code for the player sprite:

    using UnityEngine;
    using System.Collections;

    public class Blob_Scipt : MonoBehaviour {

    Vector3 velocity = Vector3.zero;
    Animator animator;

    // Use this for initialization
    void Start () {

    animator = transform.GetComponentInChildren<Animator>();

    }
    screen1.jpg
    // Update is called once per frame
    void Update () {
    if (Input.GetKeyDown (KeyCode.Space)) {

    }


    }

    void OnCollisionEnter2D(Collision2D collision)
    {

    Debug.Log("Blah");
    animator.SetTrigger("Splattrigger");

    }

    }​

    Unfortunately the game isn't responding the way I want it to so if anyone could please assist me with this issue, I'd greatly appreciate it.

    If you have any questions regarding this inquiry, please leave a reply and I'll get back to you promptly.

    Kind Regards,
    D
    screen1.jpg screen2.jpg screen3.jpg