- Home /
Renderer on object disabled after level reload
Hi
I'm sorry for a noob question, but I'm fighting with it for some time already. I've got a simple code on one object:
// Use this for initialization
void Start()
{
gameObject.SetActive(true);
gameObject.renderer.enabled=true;
}
void Awake()
{
renderer.enabled=true;
gameObject.SetActive(true);
}
// Update is called once per frame
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray,out hit))
{
if (collider.name == "start")
{
starting = true;
}
}
}
else if (Input.GetMouseButtonUp(0))
{
starting = false;
}
if (discount.animEnd)
//gameObject.SetActive (false);
renderer.enabled=false;
//Destroy (gameObject);
}
After level reload using "Application.LoadLevel(Application.loadedLevelName);", the object is not visible. Also in Inspector the renderer on the object is disabled.
Thanks in advance
why are you doing the same thing in both awake and start?
@Screenname Just a question, is awake supposed to be before start or does it not matter at all?
@Infinity Just a note that I think awake loads before start does just for all your other scripts in case you didn't know
Awake() is called before Start() and also is executed even though the gameObject is not active. If you reload the scene all scripts are executed from the beginning like when you press the play button. So my guess would be that another script is disabling your gameObject. Do you have any other scripts?
Answer by spraw · Jun 30, 2014 at 05:34 PM
void Awake()
{
renderer.enabled = true;
}
void OnLevelWasLoaded()
{
renderer.enabled = true;
}
Although I'm not sure if you need to make the class persistent, why are you completely reloading the level anyway?