So I am currently working on a project of mine and I have ran in to a problem that I just cant figure out. So the problem is this, I have created an start menu that runs a script when starting the game. Everything loads and the animations is loaded correctly BUT when I go to the main “game” scene and then go back to my “menu” scene the script just does not load. It is greyed out in the GameObject that holds the script, why does it not want to load correctly when loading from another scene but loads correctly when loading the game in the begining?
Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityEngine.Animations;
public class StartTextAnimations : MonoBehaviour
{
public float welcomeDelay = 0.2f;
public float teamTreesDelay = 0.1f;
public float animDelay = 0.5f;
public string fullWelcome;
public string fullTeamTrees;
public string currentWelcome = "";
public string currentTeamTrees = "";
public Text teamTrees;
public Text welcome;
public Text startText;
public Text quitText;
public GameObject startButton;
public GameObject quitButton;
public Animator startButtonAnim;
public Animator quitButtonAnim;
public bool startTheScene;
void Start()
{
startTheScene = true;
startButton.SetActive(false);
quitButton.SetActive(false);
startButtonAnim = startButton.GetComponent<Animator>();
quitButtonAnim = quitButton.GetComponent<Animator>();
}
void OnLevelWasLoaded(int level)
{
StartCoroutine(WelcomeText());
}
void Update()
{
if (startTheScene == true)
{
StartCoroutine(WelcomeText());
startTheScene = false;
}
if (currentWelcome.Length == 0)
{
StartCoroutine(WelcomeText());
}
}
IEnumerator WelcomeText()
{
for(int i = 0; i < fullWelcome.Length; i++)
{
currentWelcome = fullWelcome.Substring(0, i);
welcome.GetComponent<Text>().text = currentWelcome;
yield return new WaitForSeconds(welcomeDelay);
if (currentWelcome.Length == fullWelcome.Length - 1)
{
StartCoroutine(TeamTreesText());
}
}
}
IEnumerator TeamTreesText()
{
for (int i = 0; i < fullTeamTrees.Length; i++)
{
currentTeamTrees = fullTeamTrees.Substring(0, i);
teamTrees.GetComponent<Text>().text = currentTeamTrees;
yield return new WaitForSeconds(teamTreesDelay);
if (i > 10)
{
startButton.SetActive(true);
quitButton.SetActive(true);
}
}
}
public void BigStartText()
{
startText.fontSize = startText.fontSize + 10;
}
public void SmallStartText()
{
startText.fontSize = startText.fontSize - 10;
}
public void BigQuitText()
{
quitText.fontSize = quitText.fontSize + 10;
}
public void SmallQuitText()
{
quitText.fontSize = quitText.fontSize - 10;
}
public void StartGame()
{
SceneManager.LoadScene("game");
}
public void QuitGame()
{
Application.Quit();
}
}
All help is greatly appriciated, and Im sorry if the code is a bit funky and not that greatly created, im a bit new to this ![]()
