I’m trying to make a script that kills my player when it touches the lava. For some reason, it doesn’t kill it. Why?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Walking : MonoBehaviour
{
//Player rb
public Rigidbody rb;
public float MoveSpeed = 500f;
public GameObject player;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate()
{
//Arrow movement:
if (Input.GetKey(KeyCode.RightArrow))
{
rb.AddForce(Vector3.right * MoveSpeed * Time.deltaTime);
Debug.Log("RightArrow");
}
if (Input.GetKey(KeyCode.LeftArrow))
{
rb.AddForce(Vector3.left * MoveSpeed * Time.deltaTime);
Debug.Log("LeftArrow");
}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Lava")
{
Destroy(collision.gameObject);
Instantiate(player, new Vector3 (0,0,0), Quaternion.identity);
}
}
}