I started teaching myself C# about an hour ago…
But after adding conditions to my splash screen, it no longer loads the other images.
What I expected was:
Game Loads.
Splash Screen1 ( backgroundTexture1) is shown.
When any button is clicked, Splash Screen2 ( backgroundTexture2) is shown.
When any button is clicked, Game loads level 1.
what happens is:
Game Loads
Splash Screen1 ( backgroundTexture1) is shown.
When any button is clicked, Game loads level 1.
I am not shy in admitting that I just started, so I don’t know where I went wrong.
C# seemed to be pretty logical and straightforward… until my logic stopped working
using UnityEngine;
using System.Collections;
public class MainMenu : MonoBehaviour {
public Texture backgroundTexture1;
public Texture backgroundTexture2;
public int Continue;
//initialization
void Start(){
Continue = 0;
}
// Update is called once per frame
void OnGUI ()
{
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), backgroundTexture1);
if (Input.anyKeyDown Continue == 0){
Continue = 1;
}
if (Continue == 1){
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), backgroundTexture2);
}
if (Continue == 1 Input.anyKeyDown) {
Continue = 2;
}
if (Continue == 2){
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), backgroundTexture2);
}
if (Input.anyKeyDown Continue == 2){
Continue = 3;
}
if (Continue == 3){
Application.LoadLevel (1);
}
}
}
not sure if this will help but use “else if” since you say if(X=0) X = 1
and after making X=1 you ask
if(X=1) X=2
so
using UnityEngine;
using System.Collections;
public class MainMenu : MonoBehaviour {
public Texture backgroundTexture1;
public Texture backgroundTexture2;
public int Continue;
//initialization
void Start(){
Continue = 0;
}
// Update is called once per frame
void OnGUI ()
{
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), backgroundTexture1);
if (Input.anyKeyDown Continue == 0){
Continue = 1;
}else if (Continue == 1 Input.anyKeyDown) {
Continue = 2;
} else if (Input.anyKeyDown Continue == 2){
Continue = 3;
}
if (Continue == 1){
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), backgroundTexture2);
}
if (Continue == 2){
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), backgroundTexture2);
}
if (Continue == 3){
Application.LoadLevel (1);
}
}
}
thank you for the extremely fast response.
Worked perfectly.
Am I correct when I assume the reason my code did not work as expected, but yours did, is because the way I wrote it the sequence would happen within a single click of any button?
i.e: Game Loads.
Shows image 1.
anyKeyDown changes Continue to 1
but since the key has not been released,
anyKeyDown then changes Continue to 2 3 and loads the level, from a single key press?
I imagine Continue had to be getting to “3” in order for me to see the level load.
That’s my guess…
sorry for being a noob, but your answers help me ask less in the future
If im not understanding how I went wrong, then please correct me.