Hi,
Me again with my maze game (you can try here: https://dl.dropbox.com/u/2807104/labU_webp/labU_webp.html and yes I know the jump makes it too easy). I want to severely restrict the timer, which is set at 10 minutes for the game now, so that you need to pick up coins, not just for the points but to give you more time to finish a level, but I’m beating my head against a wall to do so. I have two pertinent scripts, one called On_touch_2 is attached to the coins here:
#pragma strict
var score:GameObject;
var barClock:barClock;
function Start()
{
score = GameObject.Find("Score");
}
function Update () {
}
function OnTriggerEnter() {
transform.parent.gameObject.audio.Play();
Destroy(gameObject);
++scoreScript.score;
++barClock.AddTime;
}
The other, attached to an empty GameObject is the timer, called barClock:
#pragma strict
function Awake () {
DontDestroyOnLoad (this);
clockFGMaxWidth = clockFG.width;
}
var clockIsPaused : boolean = false;
static var startTime : float; //(in seconds)
public var timeRemaining : float; //(in seconds)
var percent : float; //for bar clock
var clockBG : Texture2D; //for bar clock
var clockFG : Texture2D; //for bar clock
var clockFGMaxWidth : float; //starting width of the FG bar for bar clock
function Start()
{
startTime = 600.0; //time for the whole game
timeRemaining = startTime;
}
function Update() {
if (!clockIsPaused)
{
// make sure the timer is not paused
DoCountdown();
}
}
function DoCountdown()
{
timeRemaining -= Time.deltaTime;
percent = timeRemaining/startTime * 100; //for bar clock
if (timeRemaining < 0)
{
timeRemaining = 0;
clockIsPaused = true;
TimeIsUp();
}
ShowTime();
}
function PauseClock()
{
clockIsPaused = true;
}
function UnpauseClock()
{
clockIsPaused = false;
}
public function AddTime() { //trying to add 5 seconds to the time left
timeRemaining += 200;
}
function ShowTime() //set the variables and show the time onscreen
{
var minutes : int;
var seconds : int;
var timeStr : String;
minutes = timeRemaining/60;
seconds = timeRemaining % 60;
timeStr = minutes.ToString() + ":";
timeStr += seconds.ToString("D2");
guiText.text = timeStr; //display time
}
function TimeIsUp()
{
Application.LoadLevel("Loser");
Debug.Log("Time is up!");
}
function OnGUI() //don't forget to make the graphics GUI rather than texture!
{
var newBarWidth:float = (percent/100) * clockFGMaxWidth; // this is the width that the foreground bar should be
var gap:int = 20; // a spacing variable to help us position the clock
GUI.BeginGroup (new Rect(Screen.width - clockBG.width - gap, gap, clockBG.width, clockBG.height));
GUI.DrawTexture (Rect (0,0, clockBG.width, clockBG.height), clockBG);
GUI.BeginGroup (new Rect (5, 6, newBarWidth, clockFG.height));
GUI.DrawTexture (Rect (0,0, clockFG.width, clockFG.height), clockFG);
GUI.EndGroup ();
GUI.EndGroup ();
}
There’s stuff that doesn’t work in both scripts in my attempts to find a solution. The main problem being the On_touch_2 script with the following error:
Assets/labU/Scripts/On_touch2.js(18,20): BCE0049: Expression 'self.barClock.AddTime' cannot be assigned to.
I figure the error means that Unity is trying to applying an AddTime function from the coin itself, but nothing I do seems to fix the issue (using GetComponent and Find mainly)
Any advice?
B