I have a code in my 2D game where the player is killed when they collide with another object. However, I want to add some ground that does not kill you if you collide with it. Anyway I could achieve this? Thanks.
Here is the code for the collision if needed: (It also causes an animation to occur on death)
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class Boom : MonoBehaviour
{
private Animator animator; //this creates a variable called animator
void Awake()
{
animator = GetComponent<Animator>(); //this assigns the gameObjects Animator to the variable animator
}
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "NME")
{
//Debug.Log ("Boom", gameObject);
animator.SetBool("Collision", true); //this changes the bool parameter to true and triggers the "Boom" animation
Invoke("ChangeLevel", .5f);
}
}
void ChangeLevel()
{
SceneManager.LoadScene("SampleScene"); //this restarts the current level
}
}