Howdy, Stranger!

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

Health not showing in inspector.

using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class Player : MonoBehaviour

{

  public int fallBoundary = -20;


  [System.Serializable]

  public class PlayerStats

  {

    public int health = 100;

  }

  PlayerStats playerStats = new PlayerStats();


  private void Update()

  {

    if (transform.position.y <= fallBoundary)

    {

      DamagePlayer(999999);

    }

      

  }


  public void DamagePlayer(int damage)

  {

    playerStats.health -= damage;

    if (playerStats.health <= 0)

      GameMaster.KillPlayer(this);

  }

}

Best Answer

  • Sl0thSl0th Member
    Accepted Answer

    playerStats needs to be marked with SerializeField.

Answers

Sign In or Register to comment.