So I’ve looked up the problem and asked someone else option but to no result. I have a variable trying to reference the parents script variable and use it to update. The parent variable is updating but the variable referenced to it is not updating after its first referenced.
default parent variable:
public float time { get; private set;} //2 to 26 hours
code to refrence new variable to parent:
void Awake () {
renderColor = this.GetComponent<SpriteRenderer> ().color;
time = this.transform.GetComponentInParent<DayNightTime> ().time;
}
void FixedUpdate (){
Debug.Log (time);
if(time >= 5 && time < 8){
float percentage = ((time - 5) * 100) / 8 - 5;
renderColor = Color.Lerp(nightColor, dayColor, percentage);
}else if (time >= 19 && time < 21) {
float percentage = ((time - 19) * 100) / 19 - 21;
renderColor = Color.Lerp(dayColor, nightColor, percentage);
}
}
I’ve been a bit frustrated using different methods to see if the problem would be fixed. I’m hoping I’m not doing anything stupid but I would be grateful for someone to possibly point me in the right direction!