I have this script that checks how many cubes were collected and then the amount collected is can be used since the the count variable is a getter.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerController : MonoBehaviour {
/////////////////
/// Variables ///
/////////////////
private int count = 0;
.
.
.
public int Count {
get {
return count;
}
}
.
.
.
/////////////////////////////
/// Change score on touch ///
/////////////////////////////
void OnTriggerEnter(Collider other) {
if(other.gameObject.CompareTag("PickUp")) {
other.gameObject.SetActive(false);
count++;
UpdateScore();
}
}
///////////////////////////
/// Collected all cubes ///
///////////////////////////
void UpdateScore() {
countText.text = "Score: " + count.ToString();
if(count >= howManyToCollect.Length) {
allCollectedText.text = "All cubes collected, roll to the portal!";
}
}
}
I also have this script that is suppose to load the next level after checking if the number of cubes in the level and the number of cubes collected (used the count getter).
using UnityEngine;
using System.Collections;
public class UpdateScene : MonoBehaviour {
private GameObject[] howManyNeeded;
///////////////////////////////////
/// How many needed to continue ///
///////////////////////////////////
void Start() {
howManyNeeded = GameObject.FindGameObjectsWithTag("PickUp");
}
///////////////////////////////////////////////////////////////////
/// Change level if player touches portal & all cubes collected ///
///////////////////////////////////////////////////////////////////
void OnTriggerEnter(Collider other) {
PlayerController countFromPlayerController = new PlayerController();
if(other.gameObject.CompareTag("Portal") && howManyNeeded.Length >= countFromPlayerController.Count) {
Application.LoadLevel(Application.loadedLevel + 1);
}
}
}
I checked the console and it doesn’t show any error.
Is it even possible to change the value of a getter in the same script? Or do I have to use another variable in the UpdateScene script in the same way I used the count in the PlayerController?