I’m having a problem when trying to acces a “dontDestroyOnLoad” game object script.
After loading the new level the gameObject apears but i can’t acces the script in it.
the scenario is the following:
Scene A = Player choses a track
track info sucesfully stored in “SelectionSave” script atached to SelectionSaveObject.
SelectionSaveObject <— DontDestroyOnLoad
Scene B = Player choses a vehicle
“SelectionSave” script doesn’t work anymore.
Heres the Code:
SelectionSave.js
static var Track : int;
static var NextScreen = false;
static var Vehichle : int;
static var Go : boolean = false ;
function Awake () {
DontDestroyOnLoad (this);
}
function Update () {
if (NextScreen){
Application.LoadLevel (3);
}
if (Go){
Application.LoadLevel (Track);
}
if (Input.GetKey ("escape")){
Application.Quit ();
}
}
TrackSelection.js
var IsTrack1 = false;
var IsTrack2 = false;
var IsBack = false;
function Start ()
{
GameObject.Find ("Track1").renderer.enabled = false;
GameObject.Find ("Track2").renderer.enabled = false;
}
function OnMouseEnter ()
{
if (IsTrack1)
{
renderer.material.color = Color.green;
GameObject.Find ("Track1").renderer.enabled = true;
}
if (IsTrack2)
{
renderer.material.color = Color.green;
GameObject.Find ("Track2").renderer.enabled = true;
}
if (IsBack)
{
renderer.material.color = Color.red;
}
}
function OnMouseUp ()
{
if (IsTrack1)
{
SelectionSave.Track = 4;
SelectionSave.NextScreen = true;
}
if (IsTrack2)
{
SelectionSave.Track = 5;
SelectionSave.NextScreen = true;
}
if (IsBack)
{
SelectionSave.Track = 6;
SelectionSave.NextScreen = true;
}
}
function OnMouseExit ()
{
renderer.material.color = Color.white;
GameObject.Find ("Track1").renderer.enabled = false;
GameObject.Find ("Track2").renderer.enabled = false;
}
TruckSelection.js
var DodgeRamPrefab : Transform;
var IsDodgeRam = false;
var IsBack = false;
function Start ()
{
}
function OnMouseEnter ()
{
if (IsDodgeRam)
{
renderer.material.color = Color.green;
Instantiate (DodgeRamPrefab, GameObject.Find ("SpawnPoint").transform.position, Quaternion (0,180,0,0));
}
if (IsBack)
{
renderer.material.color = Color.red;
}
}
function OnMouseUp ()
{
if (IsDodgeRam){
Debug.Log ("Game Should be loading now");
SelectionSave.Go = true;
}
}
function OnMouseExit ()
{
renderer.material.color = Color.white;
Destroy (GameObject.Find ("DodgeRamSelection(Clone)"));
}
I have even try putting a simple function to quit the applicaton by pressing escape and nothing happens. Is like the script isn’t active.
Thx in advance.
LW.