How can I stop 3 scripts from running when a certain game object appears?
I have 3 scripts. One script is for a noun, the second is for a verb, and the third is for an adjective. There is another script that instantiates a sphere. I would like for the word scripts to stop running when the sphere instantiates and then run again after the sphere disappears. The names of the word scripts are AdjectScript, NounScript, and VerbScript and the name of the script that generates the sphere is called Appletime. Below is the word script for adjectives and the script for the sphere. What does the code look like to call a script and tell it to stop running while the sphere is visible? Thanks!
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class AdjectScript : MonoBehaviour { private int compuRanAdjective; public Text AdjText; public Text aText; float TmStart; float TmLen = 5f;
IEnumerator Start()
{
while (true)
{
compuRanAdjective = Random.Range(1, 9);
switch (compuRanAdjective)
{
case 1:
aText.text = "Beautiful";
break;
case 2:
aText.text = "Happy";
break;
case 3:
aText.text = "Good";
break;
case 4:
aText.text = "Blue";
break;
case 5:
aText.text = "Forever";
break;
case 6:
aText.text = "Amazing";
break;
case 7:
aText.text = "Sacred";
break;
case 8:
aText.text = "Immense";
break;
}
if (aText.text == "Immense")
{
yield return new WaitForSeconds(TmLen);
TmLen = 5f;
AdjText.text = "Immense";
yield return new WaitForSeconds(10);
}
if (aText.text == "Sacred")
{
yield return new WaitForSeconds(TmLen);
TmLen = 5f;
AdjText.text = "Sacred";
yield return new WaitForSeconds(10);
}
if (aText.text == "Amazing")
{
yield return new WaitForSeconds(TmLen);
TmLen = 5f;
AdjText.text = "Amazing";
yield return new WaitForSeconds(10);
}
if (aText.text == "Forever")
{
yield return new WaitForSeconds(TmLen);
TmLen = 5f;
AdjText.text = "Forever";
yield return new WaitForSeconds(10);
}
if (aText.text == "Blue")
{
yield return new WaitForSeconds(TmLen);
TmLen = 5f;
AdjText.text = "Blue";
yield return new WaitForSeconds(10);
}
if (aText.text == "Good")
{
yield return new WaitForSeconds(TmLen);
TmLen = 5f;
AdjText.text = "Good";
yield return new WaitForSeconds(10);
}
if (aText.text == "Happy")
{
yield return new WaitForSeconds(TmLen);
TmLen = 5f;
AdjText.text = "Happy";
yield return new WaitForSeconds(10);
}
if (aText.text == "Beautiful")
{
yield return new WaitForSeconds(TmLen);
TmLen = 5f;
AdjText.text = "Beautiful";
yield return new WaitForSeconds(10);
}
else
{
yield return null;
}
}
}
}
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class Appletime : MonoBehaviour {
float TmStart; // this means time start
float TmLen = 5f; // this means length of time
public Text randomTextOutcome;
public Text speechText;
public Text randomTextOutcomeAppleGhost;
public GameObject crazyApplePrefab;
private int computerRandom;
IEnumerator Start()
{
while (true)
{
computerRandom = Random.Range(1, 4);
switch (computerRandom)
{
case 1:
randomTextOutcome.text = "Apple";
break;
case 2:
randomTextOutcome.text = "Tiger";
break;
case 3:
randomTextOutcome.text = "Stick";
break;
}
if (randomTextOutcome.text == "Apple")
{
yield return new WaitForSeconds(TmLen);
int x = Random.Range(-3, 3);
int z = Random.Range(-3, 3);
TmLen = 5f;
speechText.text = "Apple";
randomTextOutcomeAppleGhost.text = "Apple";
Vector3 pos = new Vector3(x, 1, z);
GameObject crazyApple = Instantiate(crazyApplePrefab, pos, Quaternion.identity);
*****/// I think that calling the 3 scripts here to stop them from running may work but I do not know what the code looks like for that. Something like AdjecScript. something maybe.***
yield return new WaitForSeconds(10);
crazyApple.SetActive(false);
speechText.text = "".ToString();
randomTextOutcomeAppleGhost.text = "".ToString();
}
else
{
yield return null;
}
}
}