Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Problems with death script

Hello.

I'm currently making my first game and am very new to coding. I'm trying to have it so if the player touches the enemies sword then he will die.

using UnityEngine;


public class PlayerHealth : MonoBehaviour

{

  public double health;  

  void Update()

  {

    if (health <= 0)

    {

      Destroy(gameObject);

    }

  }

  private void OnCollisionEnter(Collision collision)

  {

    if (collision.gameObject.tag == "sword")

    {

      health = 0;

    }


  }

}

Any help would be appreciated thanks.

Sign In or Register to comment.