- Home /
Question by
Zypher · Jun 04, 2014 at 02:25 AM ·
score systemscoringgamecontroller
Score System?
I've been trying to modify this script, mainly line 10, so that every time I destroy a star sprite prefab I gain one point. But, all my attempts have not worked.
My Star Prefab is also being spawned through a gameController, but I'm also having trouble making a reference to GameController from my Score Script.
Here is the score script:
var score : int = 0;
function Update () {
if (Input.GetMouseButtonDown(0)) {
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit)) {
print ("Hit something: "+hit.collider.name);
if (hit.collider.name == "Cube") {
score += 1;
Debug.Log("Play again! :"+score);
Destroy(hit.collider.gameObject);
}
}
}
}
Here the GameController script:
var hazard : GameObject;
var spawnValues : Vector3;
var hazardCount : int;
var spawnWait : float;
var startWait : float;
var waveWait : float;
var scoreText : GUIText;
private var score : int;
function Start () {
score = 0;
UpdateScore ();
StartCoroutine (SpawnWaves ());
}
function SpawnWaves () {
yield WaitForSeconds (startWait);
while (true)
{
for ( var i : int= 0; i < hazardCount; i++)
{
var spawnPosition : Vector3= new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
var spawnRotation : Quaternion= Quaternion.identity;
Instantiate (hazard, spawnPosition, spawnRotation);
yield WaitForSeconds (spawnWait);
}
yield WaitForSeconds (waveWait);
}
}
function AddScore (newScoreValue : int) {
score += newScoreValue;
UpdateScore ();
}
function UpdateScore () {
scoreText.text = "Score: " + score;
}
How can I connect these to scripts so I can see the score add up with every spawned star that is destroyed?
Comment