- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
Alp-Giray-Savrum · Sep 09, 2013 at 02:19 PM ·
timestaticvaluetimer-scriptstatic variables
Static Variable Doesn't Change ?
Hello Unity Community. I'm very anixous about a code :S There's a code i translate form C# to .js
#pragma strict
///////////////////////////////////////////////////////////
var startTime : float;
var restSeconds : float;
var roundedRestSeconds : int;
var displaySeconds : float;
var displayMinutes : float;
var timeLeft : float;
static var countDownSeconds : int = 15;
var timeText : String;
///////////////////////////////////////////////////////////
function Start()
{
startTime = Time.deltaTime;
}
///////////////////////////////////////////////////////////
function OnGUI ()
{
timeLeft = Time.time - startTime;
restSeconds = countDownSeconds - (timeLeft);
roundedRestSeconds = Mathf.CeilToInt(restSeconds);
displaySeconds = roundedRestSeconds % 60;
displayMinutes = (roundedRestSeconds / 60) %60;
timeText = (displayMinutes.ToString() + ":");
///////////////////////////////////////////////////////////
if (displaySeconds > 9)
{
timeText = timeText + displaySeconds.ToString();
}
else
{
timeText = timeText + "0" + displaySeconds.ToString();
}
var textMesh : TextMesh = gameObject.GetComponent(TextMesh);
textMesh.text = timeText.ToString();
}
everthing is fine with code but I've assigned 2 more codes from outside.
First one is ;
#pragma strict
var gameOver : GameObject;
function Start () {
yield WaitForSeconds(15);
Time.timeScale = 0;
gameOver.active = true;
}
wait 15 seconds than stop whole game time. so it works fine too.
but when i try to reset counter time with this code ;
#pragma strict
var isSaveDucks = false ;
var GameOver : GameObject;
function OnMouseDown()
{
if (isSaveDucks) {
Application.LoadLevel(2);
}
if(!isSaveDucks) {
CountPoints.Score = 0;
Timer.countDownSeconds = 15;
Application.LoadLevel(Application.loadedLevel);
Time.timeScale = 1;
}
}
It does'nt work :( I must do this so please help me ! I'm Stuck.
(P.S. I'm 14 years old sorry for my bad english :/ )
Comment
The original C# code is this :
public class TimerScript : $$anonymous$$onoBehaviour {
private float startTime;
private float restSeconds;
private int roundedRestSeconds;
private float displaySeconds;
private float display$$anonymous$$inutes;
public int CountDownSeconds=120;
private float Timeleft;
string timetext;
// Use this for initialization
void Start ()
{
startTime=Time.deltaTime;
}
void OnGUI()
{
Timeleft= Time.time-startTime;
restSeconds = CountDownSeconds-(Timeleft);
roundedRestSeconds=$$anonymous$$athf.CeilToInt(restSeconds);
displaySeconds = roundedRestSeconds % 60;
display$$anonymous$$inutes = (roundedRestSeconds / 60)%60;
timetext = (display$$anonymous$$inutes.ToString()+":");
if (displaySeconds > 9)
{
timetext = timetext + displaySeconds.ToString();
}
else
{
timetext = timetext + "0" + displaySeconds.ToString();
}
GUI.Label(new Rect(650.0f, 0.0f, 100.0f, 75.0f), timetext);
}}`
Your answer
Follow this Question
Related Questions
recharging value? 0 Answers
Timer ends game 1 Answer
How do I stop 'timeSinceLevelLoad' without pausing entire game? 2 Answers
how to keep static variables or 2d array value 0 Answers
How Would I Change This To Read Within A Time Range? 1 Answer