- Home /
Question by
sleepercreeper1 · May 02, 2018 at 01:45 AM ·
inspectorvariables
getting error with code from https://unity3d.com/learn/tutorials/topics/multiplayer-networking/player-health-single-player
after following tutorial precisely, code spits out errors and doesnt have gameobject field in inspector (for healthbar)
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Health : MonoBehaviour {
public const int maxHealth = 100;
public int currentHealth = maxHealth;
public RectTransform healthBar;
public void TakeDamage(int amount)
{
currentHealth -= amount;
if (currentHealth <= 0) //< gives errors
{
currentHealth = 0;
Debug.Log("Dead!");
}
healthBar.sizeDelta = new Vector2(currentHealth, healthBar.sizeDelta.y);
}
}
Comment