[c sharp] why isn't my player dying when it touches the truck?
in this script i dont know if i have a problem but i want it so when my player touches the truck it dies... the truck and player both have rigidbodiesand box colliders please help!
Sccript on player:
using UnityEngine; using System.Collections;
public class jump : Enitity { void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.tag == "truck") Destroy(gameObject); } public float speedForce = 50f; public Vector2 jumpVector;
void Update()
{
Movement();
}
void Movement()
{
if (Input.GetKey(KeyCode.D))
{
transform.Translate(Vector2.right * 8f * Time.deltaTime);
}
if (Input.GetKey(KeyCode.A))
{
transform.Translate(Vector2.left * 8f * Time.deltaTime);
}
if (Input.GetKey(KeyCode.W))
{
transform.Translate(Vector2.up * 8f * Time.deltaTime);
}
}
}
love if someone can help cause im new (●´ω`●)
Answer by M-Hanssen · May 12, 2016 at 03:06 PM
Your code should be:
protected void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "truck") Destroy(coll.gameObject);
}
i put in your script...when i walked into the truck it still didn't kill the player... do i need to do any steps before this script???
ins$$anonymous$$doof killing the player it made the truck dissapear when touched