I’m trying to get my score (Which is a variable in a different page) to show up in a different scene. I keep getting that error, though.
//Win Screen Script
var playerScript;
playerScript = GetComponent(scriptActorPlayer);
//var buttonSize : float = 50;
//
function OnGUI()
{
GUI.Box(Rect(((Screen.width)/2)-45,(((Screen.height)/2)-25)-60,90,50), "Score: " + playerScript.score); // <- Error
if(GUI.Button(Rect(((Screen.width)/2)-45,(((Screen.height)/2)-25),90,50), "Play Again"))
{
Application.LoadLevel("sceneLevel1");
}
if(GUI.Button(Rect(((Screen.width)/2)-75,(((Screen.height)/2)-25)+60,150,50), "Return to Main Menu"))
{
Application.LoadLevel("sceneScreenMainMenu");
}
if(GUI.Button(Rect(((Screen.width)/2)-45,(((Screen.height)/2)-25)+120,90,50), "Exit Game"))
{
Application.Quit();
}
}
//Player Script
//Inspector Variables
var tagName : String; //allow the designer to setup a tag in the inspector
var rayDistance : float = 0; //length of the ray for our raycast
var score : int = 0; //score for our player
var gameTime : float = 20; //amount of time the game will last
var loadWaitTime : float = 3.0; //amount of time to wait before we load the next scene
//var numberOfPointsToWin : int = 5; //number of points to win game
//Private Variables
function Start()
{
InvokeRepeating("CountDown", 1.0, 1.0); //Repeat the countdown every second
}
//Update is called every frame
function Update ()
{
//Use mouse button to select on game objects in the scene
if (Input.GetMouseButtonDown(0))
{
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition); //get mouse position
//casts a ray against all colliders in the scene
if (Physics.Raycast(ray, hit, rayDistance))
{
if (hit.transform.tag == tagName)
{
//var position = Vector3(Random.Range(-6,6),Random.Range(-4,4),0); //new random position of the game object
//hit.transform.position = position; //move the game object to the new location
var enemyScript = hit.transform.GetComponent(scriptActorEnemy);
enemyScript.numberOfClicks -= 1; //reduce the number each click
//check that the object is at 0 before adding the points to the score
if (enemyScript.numberOfClicks == 0)
{
score += enemyScript.enemyPoint; //add points to our overall score
}
}
else
{
print ("This is not an enemy!");
}
}
}
}
function CountDown()
{
if (--gameTime == 0) //subtract from gameTime
{
CancelInvoke("CountDown"); //cancel the countdown
//if(score >= numberOfPointsToWin)
//{
Application.LoadLevel("sceneScreenWin");
//}
/*else
{
Application.LoadLevel("sceneScreenLose");
}*/
}
}
//
function OnGUI()
{
GUI.Label(Rect(10,10,100,20),"Score:" + score);
GUI.Label(Rect(10,25,100,35),"Time:" + gameTime);
}