I keep getting an error saying this…
"
NullReferenceException: Object reference not set to an instance of an object
BuildVirus.Start () (at Assets/Scripts/BuildVirus.cs:14)"
i am not quiet sure what i am not assigning though, ill post a copy of my code, if someone could help me work out what i might possibly be missing on the assigning I would be very gratefull, here is the code.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class BuildVirus : BaseVariables {
public int value;
public Slider mySlider;
public float counter = 10.0f;
void Start(){
// set reference to slider
mySlider = GetComponent<Slider>();
mySlider.maxValue = counter;
Debug.Log ("MaxVale" + mySlider.maxValue);
mySlider.value = counter;
}
void Update(){
VirusCount.text = "Virus Count: " + virus;
// TechPoints.text = "Tech Points: " + techPoints;
// vpc.text = "VPC: " + virusPerClick;
// Debug.Log ("techPoints:" + techPoints);
}
public void Clicked(){
VirusCost = 50;
// Debug.Log("techPoints before:"+techPoints);
if(techPoints >= VirusCost){
TimeCountDown();
techPoints -= VirusCost;
virus += 1;
}
// Debug.Log("techPoints after:"+techPoints);
}
public void TechPointsClicked(){
techPoints += techPointsPerClick;
{
}
}
void TimeCountDown () {
// decrement counter float with time it takes to draw each frame if its above 0;
if (counter > float.Epsilon)
{
counter-= Time.deltaTime;
}
else
{
// if the values so low, just set to 0
counter = 0;
}
// set the sliders value to counter value
mySlider.value = counter;
if (counter == 0)
{
}
}
}
thanks, been working on it for most of the day now, looking at documentation, watching videos, and trying to check out what i may be missing. so far i haven’t worked it out. thanks!