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;
}
}
}