here is the original code for a simple over the timer adder
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Displaytest : MonoBehaviour {
public UnityEngine.UI.Text Test;
public int patients;
public int reputation;
public bool stopIncrease = false;
public int newReputationValue;
void Start()
{
StartCoroutine(incoming());
}
IEnumerator incoming()
{
while (stopIncrease == false) // continue until stopIncrease == true
{
yield return new WaitForSeconds(1); // wait for 1 second
patients = patients + (Random.Range(1,5)); // increase the value
OnPatientReputationUpdated(patients); // call the function that will take care of the new value
}
}
void OnPatientReputationUpdated(int newReputationValue)
{
Test.text = "Patients: "+ newReputationValue; // update your text when your value is updated
}
}
for “newReputationValue” i want to be able to show this value while the timer ticks as text
this is my attempt but its failing miserably.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Reputation : MonoBehaviour {
public UnityEngine.UI.Text Try;
public Displaytest lumber;
public int rep;
[code=CSharp]using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Reputation : MonoBehaviour {
public UnityEngine.UI.Text Try;
public int rep;
void Update ()
{
rep = GameObject.Find("Canvas/Counter").GetComponent<Displaytest>().newReputionValue;
Try.text = "reps: "+ rep; // the problem is here but i dont understand why
Debug.Log(rep);
}
}
Ok so the second code is meant to take the newReputationValue and display it as a text,
Counter is the game object text which is a child of Canvas and has a script of Displaytest.
the problem is that the text does not display or change, it is meant to show the rate of change be it 1 to 5.