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