I can’t seem to figure why my game is not transitioning properly from the menu, to lvl 1 , to lv1 2, if you die go back to the menu. When you get to lvl 2 it takes you straight back to the menu. It has to be the clock thats screwing it up?
Here are my scripts and the webplayer. https://dl.dropbox.com/u/56545886/Pong1.2/Pong1.html
This is the script in the menu scene.
//declare the raycast objects here so we dont need to instantiate them each frame
private var ray : Ray;
private var RaycastHit : RaycastHit;
var survivalScore3DText : TextMesh;
//*****************************************
function Awake()
{
survivalScore3DText.text = "Survival Score: " + PlayerPrefs.GetInt("survivalScore").ToString();
}
function Update()
{
if(Input.GetMouseButton(0))
{
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, RaycastHit))
{
transform.position.x = RaycastHit.point.x;
}
if (RaycastHit.transform.name == "playButton")
{
audio.Play();
Application.LoadLevel("lvl1");
}
}
}
This is the script on the ball.
var mainGameScript : MainGame;
var particles_splash : GameObject;
function Awake()
{
rigidbody.AddForce(5,5,0, ForceMode.Impulse);
InvokeRepeating("IncreaseBallVelocity", 2, 2);
}
function Update()
{
//if(transform.position.y <-8)Application.LoadLevel("MenuPong");
if(transform.position.y <-8)
{
audio.Play();
mainGameScript.GameOver();
}
}
This is in another script called MainGame.js where there is a function called Game Over()
function GameOver()
{
if(points > PlayerPrefs.GetInt("survivalScore"))
{
PlayerPrefs.SetInt("survivalScore" , points);
audio.PlayOneShot(thirdSound);
}
Application.LoadLevel("MenuPong");
}
This is the timer script for the last level. So when the clock ends the game should go back to the menu for right now.
var startTime : float;
var timeRemaining : float;
function Start()
{
startTime = 31.0;
guiText.material.color = Color.red;
}
function Update()
{
Countdown();
}
function Countdown()
{
timeRemaining = startTime - Time.time;
ShowTime();
if(timeRemaining < 0)
{
timeRemaining = 0;
TimeIsUp();
}
}
function ShowTime()
{
var minutes: int;
var seconds: int;
var timeString: String;
minutes = timeRemaining /60;
seconds = timeRemaining%60;
timeString = minutes.ToString() + ":" + seconds.ToString("D2");
guiText.text = timeString;
}
function TimeIsUp()
{
Debug.Log("Time is up");
Application.LoadLevel("MenuPong");
}
This script is the regular time script
var startTime : float;
var timeRemaining : float;
function Start()
{
startTime = 31.0;
guiText.material.color = Color.red;
}
function Update()
{
Countdown();
}
function Countdown()
{
timeRemaining = startTime - Time.time;
ShowTime();
if(timeRemaining < 0)
{
timeRemaining = 0;
TimeIsUp();
}
}
function ShowTime()
{
var minutes: int;
var seconds: int;
var timeString: String;
minutes = timeRemaining /60;
seconds = timeRemaining%60;
timeString = minutes.ToString() + ":" + seconds.ToString("D2");
guiText.text = timeString;
}
function TimeIsUp()
{
Debug.Log("Time is up");
Application.LoadLevel("lvl2");
Destroy(gameObject);
}