getting parsing error(still dont know what that means)
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class health : MonoBehaviour {
public int FullHealth = 100;
public int CurrentHealth = 100;
public Slider HealthBar;
// Use this for initialization
void Start () {
//starting health
HealthBar.value = FullHealth;
}
// Update is called once per frame
void Update () {
if(col.gameObject.name == "Damage"){
HealthBar.value -= 2f;
}
}
Hi there @Gatling Hawk youtube
The parsing error you are recieving is because you have missed a curly brace at the end of the class declaration. Shown below:
public class health : MonoBehaviour
{
public int FullHealth = 100;
public int CurrentHealth = 100;
public Slider HealthBar;
// Use this for initialization
void Start () {
//starting health
HealthBar.value = FullHealth;
}
// Update is called once per frame
void Update ()
{
if(col.gameObject.name == "Damage"){
HealthBar.value -= 2f;
}
}
Without a curly brace the compiler cannot parse the file and thus throws a parsing error, simply place a curly brace at the end of the class and that error should disappear.
But, looking at your code there’s another error you’re performing a conditional check on a variable named “col” without having defined this variable anywhere. I’m assuming these lines of code:
if(col.gameObject.name == "Damage")
{
HealthBar.value -= 2f;
}
Were meant to be placed within an OnTriggerEnter/Exit or OnCollisionEnter/Exit method like so:
void OnCollisionEnter (Collision col)
{
if(col.gameObject.name == "Damage")
{
HealthBar.value -= 2f;
}
}
I hope this helps!