I am making a sorta quiz like game. and the way my script is working, is everything is inside one singular manager script. Including the buttons functions on whether it is right or wrong. Well after complications I decided to make everything a spawned prefab instead of setting active and not active. This is where the problem lies, as now when my buttons spawn, they no longer have the script reference because it’s not in their prefab.
I’ve tried making a second script then referencing the function , but I can’t do that without making everything static and thus breaking the script. Is there anyway for the prefab buttons to keep their functions ?
Moments later I find my solution on my own
Here’s what I did. I give my buttons their own script each called buttons. in this script, I call
using UnityEngine;
using System.Collections;
public class Buttons : MonoBehaviour {
public void CallAnswer(bool Correct){
GameObject QuizMaster = GameObject.FindGameObjectWithTag ("Master");
QuizMaster.GetComponent<QuizMasterController> ().Answer (Correct);
}
}
What this will do, is allow it to search for the script on a gameobject itself rather than just for the individual script. Therefor, not needing static variables.