Problems with instantiation...

I have a basic game that has seven buttons down the bottom of the screen. When one is pressed, it sets the defaultSpell variable to that spell, ranging from spell1 to spell7. However, it does not seem to work as intended. i am getting no errors, however it is not working as I want it to. It is not instantiating any others when I press the button. My two scripts are here:

  • LocalInstantiation

    using UnityEngine;
    using System.Collections;

    public class LocalInstantiation : MonoBehaviour {

     public GameObject defaultSpell;
     
     public GameObject spell1;
     public GameObject spell2;
     public GameObject spell3;
     public GameObject spell4;
     public GameObject spell5;
     public GameObject spell6;
     public GameObject spell7;
     
     public static bool spell1active;
     public static bool spell2active;
     public static bool spell3active;
     public static bool spell4active;
     public static bool spell5active;
     public static bool spell6active;
     public static bool spell7active;
     
     // Use this for initialization
     void Start () {
     	
     }
     
     // Update is called once per frame
     void Update () {
     	if(defaultSpell == null) {
     		Debug.Log("");
     	}
     	
     	if(Input.GetMouseButtonDown(0)) {
     		Ray ray;
     		RaycastHit hit;
     		ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     		if (Physics.Raycast(ray, out hit, 100.0f)) {
     			if (hit.collider.name == "Plane") 
     				Instantiate(defaultSpell, hit.point, Quaternion.identity);
     		}
     	}
     	
     	if(spell1active == true) {
     		defaultSpell = spell1;
     		
     		spell2active = false;
     		spell3active = false;
     		spell4active = false;
     		spell5active = false;
     		spell6active = false;
     		spell7active = false;
     	}
    
     	if(spell2active == true) {
     		defaultSpell = spell2;
     		
     		spell1active = false;
     		spell3active = false;
     		spell4active = false;
     		spell5active = false;
     		spell6active = false;
     		spell7active = false;
     	}
    
     	if(spell3active == true) {
     		defaultSpell = spell3;
     		
     		spell1active = false;
     		spell2active = false;
     		spell4active = false;
     		spell5active = false;
     		spell6active = false;
     		spell7active = false;
     	}
    
     	if(spell4active == true) {
     		defaultSpell = spell4;
     		
     		spell1active = false;
     		spell2active = false;
     		spell3active = false;
     		spell5active = false;
     		spell6active = false;
     		spell7active = false;
     	}
    
     	if(spell5active == true) {
     		defaultSpell = spell5;
     		
     		spell1active = false;
     		spell2active = false;
     		spell3active = false;
     		spell4active = false;
     		spell6active = false;
     		spell7active = false;
     	}
    
     	if(spell6active == true) {
     		defaultSpell = spell6;
     		
     		spell1active = false;
     		spell2active = false;
     		spell3active = false;
     		spell4active = false;
     		spell5active = false;
     		spell7active = false;
     	}
    
     	if(spell7active == true) {
     		defaultSpell = spell7;
     		
     		spell1active = false;
     		spell2active = false;
     		spell3active = false;
     		spell4active = false;
     		spell5active = false;
     		spell6active = false;
     	}
     	
     }
    

    }

  • MainGUI

    using UnityEngine;
    using System.Collections;

    public class MainGUI : MonoBehaviour {

     public Texture2D icon;
    
     void OnGUI () {
     	if(GUI.Button(new Rect(100, 500, 75, 75), new GUIContent("", icon))) {
     		LocalInstantiation.spell1active = true;
     	}
    
     	if(GUI.Button(new Rect(200, 500, 75, 75), new GUIContent("", icon))) {
     		LocalInstantiation.spell2active = true;
     	}
    
     	if(GUI.Button(new Rect(300, 500, 75, 75), new GUIContent("", icon))) {
     		LocalInstantiation.spell3active = true;
     	}
    
     	if(GUI.Button(new Rect(400, 500, 75, 75), new GUIContent("", icon))) {
     		LocalInstantiation.spell4active = true;
     	}
    
     	if(GUI.Button(new Rect(500, 500, 75, 75), new GUIContent("", icon))) {
     		LocalInstantiation.spell5active = true;
     	}
    
     	if(GUI.Button(new Rect(600, 500, 75, 75), new GUIContent("", icon))) {
     		LocalInstantiation.spell6active = true;
     	}
    
     	if(GUI.Button(new Rect(700, 500, 75, 75), new GUIContent("", icon))) {
     		LocalInstantiation.spell7active = true;
     	}
     	
     }
    

    }

Thanks in advance!

My guess would be, as it is now, you get stuck on the first spell.
I’d use an int instead of your bools…

So with arrays and an int instead of your bools, it would look something like this:

using UnityEngine; 
using System.Collections;

public class LocalInstantiation : MonoBehaviour {

	public GameObject defaultSpell;
	public GameObject[] spell = new GameObject[7];
	public static int activeSpell;
	 
	// Use this for initialization
	void Start () {
	 
	}
	 
	// Update is called once per frame
	void Update () {
		if(defaultSpell == null) 
		{
		   Debug.Log("No default spell");
		}
	 
		if(Input.GetMouseButtonDown(0)) 
		{
		   Ray ray;
		   RaycastHit hit;
		   ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		   if (Physics.Raycast(ray, out hit, 100.0f)) {
			 if (hit.collider.name == "Plane") 
			  Instantiate(defaultSpell, hit.point, Quaternion.identity);
		   }
		}
	 
	}
}

using UnityEngine;
using System.Collections;
 
public class MainGUI : MonoBehaviour {
 
    public Texture2D[] icon;
 
    void OnGUI () 
	{
	
		for(int j=0; j<7;j++)
		{
			if(GUI.Button(new Rect((j+1)*100, 500, 75, 75), new GUIContent("", icon[j]))) 
			{
				LocalInstantiation.activeSpell = j;
			}
		}
    }
}