hi , i’m trying to make a ball game. I need a help. There are coins and when i pick coins, i gain 1 point. For example , if i pick 2 coins, i have 2 points and when i fall down, episode starts again from the beginning but my score is still 2. it must be 0 after fall down. how can i reset my score after fall down ? how can i solve this? what should i add to my codes?
my scripts :
my GUI
#pragma strict
static var currentScore : int = 0;
var offsetY : float = 40;
var sizeX : float = 100;
var sizeY : float = 40;
function OnGUI () {
GUI.Box (new Rect (Screen.width/2-sizeX/2, offsetY, sizeX, sizeY), "Score: " + currentScore);
}
my coin script :
#pragma strict
var coinEffect : Transform;
var coinValue = 1;
function OnTriggerEnter (info : Collider)
{
if (info.tag == "Player")
{
GameMaster.currentScore += coinValue;
var effect = Instantiate(coinEffect, transform.position, transform.rotation) ;
Destroy(effect.gameObject, 3);
Destroy(gameObject);
}
}
and lastly, fall down script
#pragma strict
var maxFallDistance = -10;
function Update ()
{
if (transform.position.y <= maxFallDistance)
{
Application.LoadLevel("Level 1");
}
}
hi i am facing problem is that…i want to update my score when player is running…but the code i have written updating score while player is not moving
here is my code…
public class ScoreManager : MonoBehaviour
{
public Text scoreText;
public Text highscoreText;
public float scoreCounter;
public float highscoreCounter;
public float pointPerSecond;
public bool scoreIncreasing;
void Start ()
{
if (PlayerPrefs.HasKey ("HighScore"))
{
highscoreCounter = PlayerPrefs.GetFloat("HighScore");
}
}
void Update ()
{
if (scoreIncreasing)
{
//scoreCounter = scoreCounter+=1*Time.deltaTime;
scoreCounter += pointPerSecond*Time.deltaTime;
//scoreCounter += 1 ;
}
if (scoreCounter > highscoreCounter)
{
highscoreCounter = scoreCounter;
PlayerPrefs.SetFloat("HighScore" ,highscoreCounter);
//flashingText = FindObjectOfType<Loadingscene>();
//flashText.gameObject.SetActive (true);
}
scoreText.text = "Score :" + Mathf.Round(scoreCounter) ;
highscoreText.text = "High Score :" + Mathf.Round(highscoreCounter);
}