- Home /
Duplicate Question
Object reference not set to an instance of...
Basically, all i am wanting to do is pass through a value from one script (BarScript) to another (EndScreen), this value being "0.**" and then change that into a percentage to display as text in a scene. I'm sure i shouldn't be having this much trouble with it. The issue appears with the line "effiValue = BarScript.FillValue". Thanks in advance
public class EndScreen : MonoBehaviour
{
public BarScript barScript;
private float effiValue;
private double effiPercent;
void Start()
{
}
void Update()
{
effiValue = BarScript.FillValue;
effiPercent = effiValue * 100;
this.gameObject.GetComponent<Text>().text = "Efficiency: " + effiValue+ "%";
}
}
Answer by Vice_Versa · Jun 04, 2017 at 06:27 AM
instead of public BarScript barScript do public GameObject barScript; //replace line 15 with: effiValue = barScript.GetComponent().FillValue;
Answer by sohail11330 · Jun 04, 2017 at 06:31 AM
Drop the Game object with BarScript into the inspector OR in the Start function just call this line..`
void Start()
{
barScript = FindObjectOfType<barScript > ();
}
Follow this Question
Related Questions
Loading a specific set of sprites with addressables 0 Answers
Duplicating Component with Some Scene References in Serialized Scriptable Object Class Reference 0 Answers
store a reference to a float in a variable? (similar to what the "ref" keyword does) 2 Answers
Drag and drop reference not working? 1 Answer
Setting refrences in a script 2 Answers