[HELP] Trouble with simulator game script not working

I’ve been making a 3d unity game recently where two types of prefabs will spawn in a building at random times. You can compliment them so that they can be happy or insult them to make them sad. This all works fine, except that once the second prefab spawns, the script in that prefab doesn’t work. Its only the first spawned prefab that does, and I’m wondering what is wrong. I’m fairly new to unity, so I’m probably going about this the wrong way. Help would really be appreciated, the scripts related to the issue are below. (I don’t get any error messages)

Spawner Script:

[LIST=1]
[*]public GameObject[] enemies;
[*]public Vector3 spawnValues;
[*]public float spawnWait;
[*]public float spawnMostWait;
[*]public float spawnLeastWait;
[*]public GameObject radio;
[*]public GameObject studentText;
[*]public int startWait;
[*]public bool stop;
[*]int randEnemy;
[*]// Use this for initialization
[*]void Start () {
[*]     StartCoroutine(waitSpawner());
[*]}
[*]// Update is called once per frame
[*]void Update () {
[*]     spawnWait = Random.Range(spawnLeastWait, spawnMostWait);
[*]}
[*]IEnumerator waitSpawner()
[*]{
[*]     yield return new WaitForSeconds(startWait);
[*]     while (!stop)
[*]     {
[*]         randEnemy = Random.Range(0, 2);
[*]         Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), 0, Random.Range(-spawnValues.z, spawnValues.z));
[*]         Instantiate(enemies[randEnemy], spawnPosition + transform.TransformPoint(0, 0, 0), gameObject.transform.rotation);
[*]         studentText.SetActive(true);
[*]         yield return new WaitForSeconds(2);
[*]         studentText.SetActive(false);
[*]         yield return new WaitForSeconds(spawnWait);
[*]     }
[*] 
[*]}
[*]}
[/LIST]

Female Prefab Script that doesn’t work after second spawn:

[LIST=1]
[*]public GameObject gameManager;
[*]public int happiness = 0;
[*]public int sadness = 0;
[*]public int musicHappiness = 0;
[*]public Material happyMaterial;
[*]public Material neutralMaterial;
[*]public Material sadMaterial;
[*]// Use this for initialization
[*]void Start()
[*]{
[*]     gameManager = GameObject.FindGameObjectWithTag("GameManager");
[*]     print("script working");
[*]}
[*]// Update is called once per frame
[*]void Update()
[*]{
[*]     if (gameManager.GetComponent<ManageScript>().complimentGirl == true)
[*]{
[*]         happiness = happiness + 1;
[*]         sadness = sadness - 1;
[*]         gameManager.GetComponent<ManageScript>().complimentGirl = false;
[*]     }
[*]     if (gameManager.GetComponent<ManageScript>().insultGirl == true)
[*]{
[*]         sadness = sadness + 1;
[*]         happiness = happiness - 1;
[*]         gameManager.GetComponent<ManageScript>().insultGirl = false;
[*]     }
[*]     if (gameManager.GetComponent<ManageScript>().leaveGirl == true)
[*]{
[*]         print("Left Girl");
[*]         gameManager.GetComponent<ManageScript>().leaveGirl= false;
[*]     }
[*]     if (happiness >= sadness)
[*]     {
[*]         GetComponent<Renderer>().material = happyMaterial;
[*]     }
[*]     if (happiness <= sadness)
[*]     {
[*]         GetComponent<Renderer>().material = sadMaterial;
[*]     }
[*]     if (happiness == sadness)
[*]     {
[*]         GetComponent<Renderer>().material = neutralMaterial;
[*]     }
[*]     if (gameManager.GetComponent<ManageScript>().musicIsOn == true)
[*]     {
[*]         musicHappiness = 1;
[*]         happiness = happiness + musicHappiness;
[*]         gameManager.GetComponent<ManageScript>().musicIsOn = false;
[*]     }
[*]     if (gameManager.GetComponent<ManageScript>().musicIsOff == true)
[*]     {
[*]         musicHappiness = -1;
[*]         happiness = happiness + musicHappiness;
[*]         gameManager.GetComponent<ManageScript>().musicIsOff = false;
[*]     }
[*]}
[*]void OnMouseDown() {
[*]     print("Talking is working");
[*]     gameManager.GetComponent<ManageScript>().freezeMove();
[*]     gameManager.GetComponent<ManageScript>().girlTalk();
[*]}
[*]}
[/LIST]

Again, this is kind of weird because the other scripts in these prefabs work no matter what, I’ve tested a print on start on these scripts to see if they run at all and they don’t seem to.
Male Prefab Script that doesn’t work after second spawn:

[LIST=1]
[*]public GameObject gameManager;
[*]public int happiness = 0;
[*]public int sadness = 0;
[*]public int musicHappiness = 0;
[*]public Material happyMaterial;
[*]public Material neutralMaterial;
[*]public Material sadMaterial;
[*]// Use this for initialization
[*]void Start()
[*]{
[*]     gameManager = GameObject.FindGameObjectWithTag("GameManager");
[*]     print("script working");
[*]}
[*]// Update is called once per frame
[*]void Update()
[*]{
[*]     if (gameManager.GetComponent<ManageScript>().complimentBoy == true)
[*]     {
[*]         happiness = happiness + 1;
[*]         sadness = sadness - 1;
[*]         gameManager.GetComponent<ManageScript>().complimentBoy = false;
[*]     }
[*]     if (gameManager.GetComponent<ManageScript>().insultBoy == true)
[*]     {
[*]         sadness = sadness + 1;
[*]         happiness = happiness - 1;
[*]         gameManager.GetComponent<ManageScript>().insultBoy = false;
[*]     }
[*]     if (gameManager.GetComponent<ManageScript>().leaveBoy == true)
[*]     {
[*]         print("Left Boy");
[*]         gameManager.GetComponent<ManageScript>().leaveBoy = false;
[*]     }
[*]     if (happiness >= sadness)
[*]     {
[*]         GetComponent<Renderer>().material = happyMaterial;
[*]     }
[*]     if (happiness <= sadness)
[*]     {
[*]         GetComponent<Renderer>().material = sadMaterial;
[*]     }
[*]     if (happiness == sadness)
[*]     {
[*]         GetComponent<Renderer>().material = neutralMaterial;
[*]     }
[*]     if (gameManager.GetComponent<ManageScript>().musicIsOn == true)
[*]     {
[*]         musicHappiness = 1;
[*]         happiness = happiness + musicHappiness;
[*]         gameManager.GetComponent<ManageScript>().musicIsOn = false;
[*]     }
[*]     if (gameManager.GetComponent<ManageScript>().musicIsOff == true)
[*]     {
[*]         musicHappiness = -1;
[*]         happiness = happiness + musicHappiness;
[*]         gameManager.GetComponent<ManageScript>().musicIsOff = false;
[*]     }
[*]}
[*]void OnMouseDown()
[*]{
[*]     print("Talking is working");
[*]     gameManager.GetComponent<ManageScript>().freezeMove();
[*]     gameManager.GetComponent<ManageScript>().boyTalk();
[*]}
[/LIST]
  • }

That’s a lot of code, and not formatted.
You’re new, though, so that happens a lot here. Please read this page to see how you can insert code properly on the forums. Using code tags properly
It would be great if you edited your post… People coming to look at this thread will have a much easier time trying to assist you. :slight_smile:

If it doesn’t print from the start, then the script is disabled for some reason. You should be able to look at it in the editor when the game is running by highlighting the object and see if the box is not checked. If so, you have to find out why the second cloned prefab has a disabled script.

Okay, so I edited the forum and looked at my game again. My script does not become disabled, yet it doesn’t print either.