Hi!
I’m working on my game’s save function, and this code is part of it. What I want it to do is turn on certain GameObjects when certain floats equal one. Here’s the code…
var chapter1 : float;
var chapter2 : float;
var chapter3 : float;
var chapter4 : float;
var chapter5 : float;
var chapter6 : float;
var chapter7 : float;
var chapter8p1 : float;
var chapter8p2 : float;
var playedOnce : float;
var playedTwice : float;
function Start () {
}
function Update () {
if (Application.loadedLevel == 4)
{
chapter1 = 1;
chapter2 = 0;
chapter3 = 0;
chapter4 = 0;
chapter5 = 0;
chapter6 = 0;
chapter7 = 0;
chapter8p1 = 0;
chapter8p2 = 0;
}
if (Application.loadedLevel == 5)
{
chapter1 = 0;
chapter2 = 1;
chapter3 = 0;
chapter4 = 0;
chapter5 = 0;
chapter6 = 0;
chapter7 = 0;
chapter8p1 = 0;
chapter8p2 = 0;
}
if (Application.loadedLevel == 8)
{
chapter1 = 0;
chapter2 = 0;
chapter3 = 1;
chapter4 = 0;
chapter5 = 0;
chapter6 = 0;
chapter7 = 0;
chapter8p1 = 0;
chapter8p2 = 0;
}
if(chapter1 == 1)
{
GameObject.Find("Chapter 1").SetActive(true);
}
if(chapter1 == 0)
{
GameObject.Find("Chapter 1").SetActive(false);
}
if(chapter2 == 1)
{
GameObject.Find("Chapter 2").SetActive(true);
}
if(chapter2 == 0)
{
GameObject.Find("Chapter 2").SetActive(false);
}
if(chapter3 == 1)
{
GameObject.Find("Chapter 3").SetActive(true);
}
if(chapter3 == 0)
{
GameObject.Find("Chapter 3").SetActive(false);
}
if(chapter4 == 1)
{
GameObject.Find("Chapter 4").SetActive(true);
}
if(chapter4 == 0)
{
GameObject.Find("Chapter 4").SetActive(false);
}
if(chapter5 == 1)
{
GameObject.Find("Chapter 5").SetActive(true);
}
if(chapter5 == 0)
{
GameObject.Find("Chapter 5").SetActive(false);
}
if(chapter6 == 1)
{
GameObject.Find("Chapter 6").SetActive(true);
}
if(chapter6 == 0)
{
GameObject.Find("Chapter 6").SetActive(false);
}
if(chapter7 == 1)
{
GameObject.Find("Chapter 7").SetActive(true);
}
if(chapter7 == 0)
{
GameObject.Find("Chapter 7").SetActive(false);
}
if(chapter8p1 == 1)
{
GameObject.Find("Chapter 8 - 1").SetActive(true);
}
if(chapter8p1 == 0)
{
GameObject.Find("Chapter 8 - 1").SetActive(false);
}
if(chapter8p2 == 1)
{
GameObject.Find("Chapter 8 - 2").SetActive(true);
}
if(chapter8p2 == 0)
{
GameObject.Find("Chapter 8 - 2").SetActive(false);
}
if(playedOnce == 1)
{
GameObject.Find("Played Once").SetActive(true);
}
if(playedOnce == 0)
{
GameObject.Find("Played Once").SetActive(false);
}
if(playedTwice == 1)
{
GameObject.Find("Played Twice").SetActive(true);
}
if(playedTwice == 0)
{
GameObject.Find("Played Twice").SetActive(false);
}
}
function Awake () {
DontDestroyOnLoad (transform.gameObject);
}
My only issue is that because of the final Awake function, I can’t put the GameObjects I’m trying to turn on and off in the code as variables. How could I make this code work without setting any of the GameObjects as variables, and instead make the code search the scene for an Object named that? I’m really bad at explaining this kind of stuff, so if you have any questions, feel free to ask!