- Home /
Changing something in another scene by answering correctly
I'm making a guess the movie game, and I wondered if anybody know how I can make it so. When a person answers correctly, the button with a image on the other scene needs to change. So I need a script that changes puts a image or something over the button on the other scene. This is the script that that i need to put it in------ using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.SceneManagement;
public class Spawn: MonoBehaviour {
private string gameName;
private int countGuess;
[SerializeField]
private InputField input;
[SerializeField]
private Text text;
void Awake(){
gameName = "spawn";
text.text = "Guess The Name Of The Game";
}
public void GetInput(string guess){
CompareGuesses(guess);
input.text = "";
}
public void CompareGuesses (string guess){
if (guess == gameName) {
text.text = "You Guessed Correctly";
SceneManager.LoadScene("Level 1");
} else if (guess != gameName) {
text.text = "Wrong!";
} else if (guess != gameName) {
text.text = "Wrong!";
}
}
}
Add a few gameobjects in your variables and have a specific one spawn when a seperate script knows the answer is true. $$anonymous$$eep that script in a do not destroy functions, Preferably make an empty game object that detects which button is clicked through public variables and have that go through to the next scene. then have the next scene look at the game object that has now been carried on and have it detect weather or not the before answer was correct (true) or wrong (false) when wrong have it spawn in the "wrong" object you want and when correct have it spawn in the correct object. If you would like i can give you an example, that might be hard to understand.
It would be great if you could make an example for me. I'm pretty new to scripting so I need a loot of help :)
Answer by Rodoleia · Jul 30, 2016 at 04:35 PM
@KristianGrytdal If you have a lot of different scenes in your game and you want to transfer a data bettween them, i think you need some GlobalManager object, wich will present in your game constantly, no matter what scene is active now.
The most simple way to achieve this is to create gameobject with attached GlobalManager script to it in your initial scene. Then you just add DontDestroyOnLoad method to this script (https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html) and it will be not destroyed when you load any others scene. You can store any data you need in this script, and then load any scene with corrent parameters (button images etc), extracted from it.
Here is a bit more complicated, but globally more correct way to create a GlobalManager object as a singleton(it ensurance that it will be only one GlobalManager object in your game): https://unity3d.com/ru/learn/tutorials/projects/2d-roguelike-tutorial/writing-game-manager if you don't know what singleton is, chech this out: https://en.wikipedia.org/wiki/Singleton_pattern
So I if i make a image an put the Global$$anonymous$$anager and DontDestroyOnLoad script on it, in the scene that dosn't have the InputField. Then I go to the scene with the InputField, and should be able to find it there. But do I need to do something with the script that is on the InputField(The script that says what happends when a person answers correctly) . or how do i do it so the image becomes visible when the person answers correctly?.
Your answer
Follow this Question
Related Questions
Making an image appear from a different script 0 Answers
How do i check if correct image is dragged in the panel?? 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Change Scene by answering right 3 Answers