Help with clearing bugs in this C# script

Hey I need help. I made a script and Im having allot of troubles. When I press “I” It unlocks the mouse and brings up the GUI spawn menu and when I press it again it it closes but if I click on a button and spawn something it locks the mouse again and When I press “I” it unlocks the mouse again but it doesnt hide the buttons again also I want the Mouse look script to be disabled when the spawn menu is showing and enabled when its being hidden. How do I fix this (including the mouse locking again when something is spawned) Here is the script:

using UnityEngine;
using System.Collections;
 
public class SpawnGui : MonoBehaviour 
{

    private bool showGUI;
	public bool lockCursor = true; 
	public Transform Cube;
	public Transform Cuboid;
	public Transform BlockHead;
	public bool CubeC;
	public bool CuboidC;
	public bool BlockHeadC;
	
	void OnMouseDown ()
	{
	
	}
	
	
	void Start () 
    {
       showGUI = false;
		
		Screen.lockCursor = true;
		
		if(Input.GetKeyDown(KeyCode.Escape))
		{
			Application.LoadLevel(0);
		}
		
		
	}
		
	
		
	
    void Update () 
    {
	
		if(CuboidC)
		{
		    if (Input.GetMouseButtonDown(1))
			renderer.material.color = Color.red;
			
		    if (Input.GetMouseButtonUp(1))
		    {
            Destroy(gameObject);
	        }
		}
		if(CubeC)
		{
		    if (Input.GetMouseButtonDown(1))
			renderer.material.color = Color.red;
			
		    if (Input.GetMouseButtonUp(1))
		    {
            Destroy(gameObject);
	        }
		}
		if (BlockHeadC)
		{
		    if (Input.GetMouseButtonDown(1))
			renderer.material.color = Color.red;
			
		    if (Input.GetMouseButtonUp(1))
		    {
            Destroy(gameObject);
	        }
		}

       if(Input.GetKeyDown(KeyCode.I))
       {
			
		
			
         
      
       
         if(showGUI == true)
         {
          showGUI = false;
		  Screen.lockCursor = true;
         }
 
 
         else if(showGUI == false)
         {
          showGUI = true;
		  Screen.lockCursor = false;
         }
			
			
	      
       }
    }
 

    void OnGUI()
    {
      
       if(showGUI == true)
       {
         if(GUI.Button(new Rect(20,20,100,80), "Cube"))
         {
		   Instantiate(Cube,GameObject.Find("spawnPoint").transform.position, Quaternion.identity);
         }
			
		 if(GUI.Button(new Rect(20,120,100,80), "Cuboid"))
         {
		   Instantiate(Cuboid,GameObject.Find("spawnPoint").transform.position, Quaternion.identity);
         }
			
		 if(GUI.Button(new Rect(20,220,100,80), "BlockHead"))
         {
		   Instantiate(BlockHead,GameObject.Find("spawnPoint").transform.position, Quaternion.identity);
         }
 
       }
    }
	
	
	
}

Could you explain your first problem a little more I’m not seeing the problem you say you encounter when you click the GUI button.

Assuming that the MouseLook script is attached to the same gameobject as this script you can use

		if(Input.GetKeyDown(KeyCode.I))
		{
        	if(showGUI == true)
			{
				showGUI = false;
         		Screen.lockCursor = true;
				gameObject.GetComponent<MouseLook>().enabled = true;
			}	
	        else if(showGUI == false)
	        {
	        	showGUI = true;
	         	Screen.lockCursor = false;
				gameObject.GetComponent<MouseLook>().enabled = false;
	        }
		}

If not you will have to use a reference to the MouseLook component.