Collision and reaction Unity 3d

2

I have a doubt in a script, I'm creating a game made in 3d unity. The question is, how do I identify the collision between 2 objects and add a jump action to one of those objects, if anyone can help, I 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;
        }

    }

}
    
asked by anonymous 02.04.2016 / 19:29

2 answers

0

The solution is simply to switch% from% to% with%.

    
02.04.2016 / 19:50
1

As Pablo said change Collider2D to Collision2D and make sure your floor object is tagged floor.

    
04.04.2016 / 16:16