- Home /
Scripts stop working after closing Unity?
Sorry, if this is a silly question but I'm new to Unity and scripting. I followed a tutorial to make an interactive game object and it works fine until I close Unity/load up a different scene. The code looks like this:
using UnityEngine;
using System.Collections;
public class objectSelect : MonoBehaviour {
public RaycastHit hit;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void LateUpdate () {
Ray ray = Camera.main.ScreenPointToRay (new Vector3 (Screen.width / 2, Screen.height / 2, 0));
if (Physics.Raycast (ray, out hit, 3)) {
if (hit.collider.gameObject.GetComponent<highlightInteract> () != null) {
hit.collider.gameObject.GetComponent<highlightInteract> ().OnLookEnter ();
}
}
}
}
thanks in advance
Do you mean when you build the scene it doesn't work? I don't quite understand your question.
Answer by Andres-Fernandez · Apr 16, 2014 at 08:20 AM
Everytime you close a scene all objects are destroyed. If you want any object to stay permanently between scenes you have to use function DontDestroyOnLoad: http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
why when i try to add my script to the "player" it says can not can not add script 1 Answer
Web Build load external C# Script 0 Answers
How to activate a specific script in a Prefab. 2 Answers
InGame Interactive Computer 0 Answers