Hi all, im making my game but im having problem.
Basically i have timer to count down from 2 seconds to 0 and if it reaches 0 it stops [timescale is 0] + it shows UI, so that works but when i hit the Try again button it does restart sets timer back to 2 and UI is gone but the player doesnt move its still frozen same with the timer its stuck at 2 even though i have set TimeScale to go back to 1 before loading level.
Another problem question is how to make my player [its moving from A to B and then back] but how do i make it when i press button lets say when i press ‘leftarrow’ then even though it didnt reached point B it will go back to A
Im struggling with this a bit i would really appreciate if someone could help
#pragma strict
public function TryAgain()
{
Debug.Log("TryAgain");
Time.timeScale = 1;
Application.LoadLevel (0);
}
public function Quit()
{
Debug.Log("you quit");
Application.Quit();
}
Here is the code im using for UI buttons
var pointB : Transform;
var pointA : Transform;
var speed = 1.0;
function Start ()
{
while (true) {
var i = Mathf.PingPong(Time.time * speed, 1);
transform.position = Vector3.Lerp(pointA.position, pointB.position, i);
yield;
}
}
Here is the code for player // moving from a to B
#pragma strict
var timer : float = 2.0;
var isdead : boolean = false;
var MenuSkin : GUISkin;
var menu : GameObject;
private var isShowing : boolean;
function Update()
{
timer -= Time.deltaTime;
if(timer <= 0)
{
timer = 0;
//die show menu reset etc
isdead = true;
}
if(isdead)
{
Dead();
}
}
function Dead()
{
isShowing = true;
menu.SetActive(isShowing);
Time.timeScale = 0;
}
function OnGUI()
{
GUI.skin = MenuSkin;
GUI.Box(Rect(10, 10, 100, 80), "" + timer.ToString("0.0"));
}
And here is code for timer and death detection attached to player
The player has rigidbody 2d and boxcollider 2d
Thanks for helping guys !