- Home /
How can i make score keep updating after bool condition has been met on looping objects?
So my problem is i have a score that updates by 10points after the objects pass a specific coordinate. The thing is i have to objects to loop back to the starting poistion after they reach a certain coordinate so they can be run again. The thing is when they reach the score point nothing happens, an my guess is that it is becuase they pass the point once already, heres a script to help
using UnityEngine;
using System.Collections;
public class scoredisplay : MonoBehaviour {
public static int scoreValue;
public GUIText guiScore;
private Transform Obstacle;
bool hasAwardedPoints = false;
void Awake() {
DontDestroyOnLoad (gameObject);
}
// Use this for initialization
void Start () {
Obstacle = transform;
scoreValue = 0;
guiScore.text = "Score: 0";
}
// Update is called once per frame
void Update () {
if (Obstacle.position.x < -12.5f && !hasAwardedPoints) {
scoreValue += 10;
guiScore.text = "Score: " + scoreValue;
hasAwardedPoints = true;
}
Answer by robusto · Jun 08, 2014 at 03:56 PM
Where you reset the position of object, that is where you need to reset the hasAwardedPoints back to false. If you are using MonoDevelop you can right click hasAwardedPoints where you declared it at the top of this script and click refactor and click Create Property so it will give you a getter/setter which can be modified from another script that I presume is resetting the object's position.
ok when i do as you say it gives me the option to select up/down to pick new location, not sure what to do from there
not sure what to do when it says select up/down for new location and how do i modify it from another script afterwards