hey all, so im working on a score system for my game and came across a small issue.
now depending on the amount of shots taken, the player will be awarded 1 to 4 stars. (4 being the best), now my script worked fine when i just had a debug.log that said the number of stars won. however now ive added in the GUI graphics and it doesn’t work, only one star shows up nomatter what the score is :S
here is a shot of my gui http://i.imgur.com/y1AFeuI.png
and here is the code i wrote, any ideas?
using UnityEngine;
using System.Collections;
public class Hole_TouchDestroy : MonoBehaviour {
public GUITexture ScoreBack;
public GUITexture Star1;
public GUITexture Star2;
public GUITexture Star3;
public GUITexture Star4;
public GUITexture StarSurround;
void OnTriggerEnter(Collider other) {
Destroy(other.gameObject);
Debug.Log(DragShotMover.parCount);
ScoreBack.enabled = true;
if (DragShotMover.parCount <= 2 )
Debug.LogWarning("4 Stars");
Star1.enabled = true;
Star2.enabled = true;
Star3.enabled = true;
Star4.enabled = true;
StarSurround.enabled = true;
if (DragShotMover.parCount == 3 )
Debug.LogWarning("3 Stars");
Star1.enabled = true;
Star2.enabled = true;
Star3.enabled = true;
Star4.enabled = false;
StarSurround.enabled = false;
if (DragShotMover.parCount == 4 )
Debug.LogWarning("2 Stars");
Star1.enabled = true;
Star2.enabled = true;
Star3.enabled = false;
Star4.enabled = false;
StarSurround.enabled = false;
if (DragShotMover.parCount >= 5 )
Debug.LogWarning("1 Star");
Star1.enabled = true;
Star2.enabled = false;
Star3.enabled = false;
Star4.enabled = false;
StarSurround.enabled = false;
//Application.LoadLevel(1);
DragShotMover.parCount = 0;
}
}
You are missing {} around all of your if statements. That is, the only thing that is controlled by your if statements is the Debug.Log() call. All other lines are executed, and the last set of lines is for one star. But even if you had your brackets, you would need ‘else’ clauses to get the logic right. Try this simplification instead:
public class Hole_TouchDestroy : MonoBehaviour {
public GUITexture ScoreBack;
public GUITexture Star1;
public GUITexture Star2;
public GUITexture Star3;
public GUITexture Star4;
public GUITexture StarSurround;
void OnTriggerEnter(Collider other) {
Destroy(other.gameObject);
Debug.Log(DragShotMover.parCount);
ScoreBack.enabled = true;
var count = DragShotMover.parCount;
StarSurround.enabled = Count <= 2;
Star1.enabled = count <= 2;
Star2.enabled = count <= 3;
Star3.enabled = count <= 4;
Star4.enabled = count <= 5;
DragShotMover.parCount = 0;
}
}