Hey there.
Im finishing hte tutorial but now I found this problem. The UpdateScore() method is only called at the very first frame. I triend placing a call to this method into a Update() method and it worked perfectly, so I asume the problem is not ON the UpdateScore() method, but IS the method itself.
Sorry if I mispelled something, I´m Spanish and my English is not all it could be.
Here is the code:
public class gameController : MonoBehaviour {
public GameObject hazard;
private Vector3 hazardPosition;
public int hazardCount;
public float startWait;
public float spawnWait;
public float waveWait;
private int score;
public GameObject scoreText;
void Start ()
{
SpawnWaves();
StartCoroutine (SpawnWaves());
score = 0;
UpdateScore();
}
IEnumerator SpawnWaves()
{
while (true)
{
yield return new WaitForSeconds(startWait);
for (int i = 0; i <= hazardCount; i++)
{
hazardPosition = new Vector3 (Random.Range(-5, 5), Random.Range (-5, 5), 20);
Instantiate(hazard, hazardPosition, Quaternion.identity);
yield return new WaitForSeconds(spawnWait);
}
yield return new WaitForSeconds(waveWait);
}
}
public void adScore(int scoreValue)
{
score = score + scoreValue;
}
void UpdateScore ()
{
scoreText.GetComponent<GUIText>().text = "score: " + score;
}
}
And:
public class arteroid : MonoBehaviour
{
public float rotacion;
private Rigidbody rb;
public GameObject explosion;
public float speed;
private gameController gameController;
public int scoreValue;
void Start()
{
rb = GetComponent<Rigidbody>();
rb.angularVelocity = Random.insideUnitSphere * rotacion;
rb.velocity = transform.forward * (-speed);
GameObject gameControllerObject = GameObject.FindWithTag("GameController");
if (gameControllerObject != null)
{
gameController = gameControllerObject.GetComponent<gameController>();
}
else { Debug.Log("se ha encontrado el script 'gameController'"); }
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "capsule") { return; }
DestroyObject(other.gameObject);
DestroyObject(gameObject);
Instantiate(explosion, rb.transform.position, rb.transform.rotation);
gameController.adScore(scoreValue);
}
}
Thanks a lot for whoever replies me