Hey there,
I am following a tutorial by a youtuber called Jimmy Vegas, and I stumbled across this error (see the image I uploaded)
Here is the script, what am I doing wrong?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HealthMonitor : MonoBehaviour {
public static int HealthValue;
public int InternalHealth;
public GameObject Heart1;
public GameObject Heart2;
public GameObject Heart3;
void Start () {
}
void Update () {
InternalHealth = HealthValue;
if (HealthValue) == 1) {
Heart1.SetActive (true);
if (HealthValue) == 2) {
Heart2.SetActive (true);
if (HealthValue) == 3) {
Heart3.SetActive (true);
}
}
}
}
}
nat42
October 24, 2017, 9:52am
2
Something ate some openning braces “if (HealthValue) == 1) {” needs to be “if ((HealthValue) == 1) {” or “if (HealthValue == 1) {”
Formatted.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HealthMonitor : MonoBehaviour {
public static int HealthValue;
public int InternalHealth;
public GameObject Heart1;
public GameObject Heart2;
public GameObject Heart3;
void Start () {
}
void Update () {
InternalHealth = HealthValue;
if (HealthValue == 1) {
Heart1.SetActive (true);
}
if (HealthValue == 2) {
Heart2.SetActive (true);
}
if (HealthValue == 3) {
Heart3.SetActive (true);
}
}
}
If you see someone who needs to know about code tags, please link them to this post:
Please use code tags when posting code.
You can “tag” your code by typing [984347--130826--Screenshot 2015-03-16 10.33.58.png] around your code.
There is no overt “Code” tag button that automatically tags a selection as code.
That being said, however, we can Insert code directly into the post using the “Insert Code” button:
[image]
This will bring up an “Insert” window were we can paste our code and choose…
Please do use code tags, makes things so much easier to read.
This is not correct:
if (HealthValue) == 1)
For every opening “(” you must have a closing “)”.