Question by
RageevanGames · Nov 24, 2016 at 01:11 PM ·
collisiondead
Need help with dead for my player on collision with my enemy.
Hey fellow game developers, im new to unity i just started for 2 days ago, and i cant make this script work. I rely on this for my whole game to work, for an school project. The real problem is that when i press game and go to my enemy, nothing happens, ive made a script so i can kill it, but how do i make it kill me once it just touches me? And i want my player to die, and restart the game level if possible?
using UnityEngine; using System.Collections;
public class damagePlayer : MonoBehaviour {
public int playerHealth = 10;
int damage = 10;
private object _collision;
void OnCollisionEnter(Collision _collision)
{
if (_collision.gameObject.tag == "Enemy")
{
playerHealth -= damage;
}
if (playerHealth <= 0) // If Healht is less than or equal to 0
{
Destroy(gameObject); // Destroy GameObject
}
}
Comment