- Home /
Unknown issue with score system
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;
}
}
Answer by robertbu · Aug 05, 2013 at 05:17 PM
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;
}
}
i knew it would of been something simple, been staring at the screen all day! lol Thankyou for your help, and thankyou even more for simplifying the script, works great!
ooh small question.. my next step is to make a 1 or 2 seconds to pass before each star is enabled, so 1 star would show, wait for 1 second, second star shows ect. How would i go about this using this script?
You would put this between your enabled calls:
yield WaitForSeconds (1.0);
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Scoring help ! 1 Answer
Score System help 1 Answer
How to add score after destroying object in unity 2D? 1 Answer
Add score when enemy is killed? 2 Answers