Collision and Unity 3d reaction

Asked

Viewed 1,197 times

2

I have a doubt in a script, I am creating a game made in Unity 3d. The doubt and the following, as I do to identify the collision between 2 objects and add a jump action to one of these objects, if anyone can help thank you very much.

Code - does not work:

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {
    public Vector2 jump = new Vector2(0,200);
     public Collider2D coli;
    private Rigidbody2D rb;
    private Transform tmf;

    // Use this for initialization
    void Start () {
        rb = GetComponent<Rigidbody2D>();
        tmf = GetComponent<Transform>();

    }

    // Update is called once per frame
    void Update () {

    }
     void OnCollisionEnter2D(Collider2D coll)
    {
        if (coll.gameObject.tag == "piso")
        {
            //rb.velocity = Vector2.zero;
            // rb.AddForce(jump);
            Vector2 vt2 = tmf.localPosition;
            vt2.y = 2f;
            tmf.localPosition = vt2;
        }

    }

}

2 answers

1

As Pablo said swap the Collider2d for Collision2d and check if your floor object is tagged with floor.

0


The solution is simply to exchange Collider2D for Collision2D.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.