How can I write a more efficient script for changing scenes from a map scene?
Hi I am wondering how I might go about writing a more efficient script that handles all the scene changes that can occur on a map. I have several pin points that when clicked take you to a different scene and at the moment I basically have the same script on each different game object (pin) but im wondering if there is a better way to do this? This is an example of one of the scripts I have on the pins currently:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;
public class SceneChange : MonoBehaviour {
private void OnMouseDown()
{
SceneManager.LoadScene("PinOne");
}
}
Hopefully someone can help, thanks in advance :)
Answer by PhilipaCarruthers · Dec 06, 2020 at 04:03 AM
Hi just wanted to update for followers of this question I managed to solve this with the following code:
public string sceneName;
private void OnMouseDown()
{
if (sceneName != null)
{
SceneManager.LoadScene(sceneName);
}
}
This way you can add the scene you want to change to into the 'scene name' box in the inspector once you attach the script to each object (in this case the pins on the map)
Your answer
Follow this Question
Related Questions
Changing scene by clicking on a game object 1 Answer
How to Stop All Game Sound in All Scenes by simply pressing On/Off Button 2 Answers
PreloadData is missing. It should always be there. 1 Answer
Scene transition from right to left 0 Answers
How do I trigger a function right after a additive scene ends? 0 Answers