Why this error when trying to instantiate object ?(Solved)

ok, I have a small script that randomly picks a location and instantiates an object there. but for some reason I’m getting this error -

Assets/SetRandomButton.cs(30,28): error CS0266: Cannot implicitly convert type UnityEngine.Object' to UnityEngine.GameObject’. An explicit conversion exists (are you missing a cast?)

here is the script -

using UnityEngine;
using System.Collections;

public class SetRandomButton : MonoBehaviour
{

	public Transform[] buttonLocation;
	public static bool activeButton = true;
	public GameObject cannonButton;
	public static bool buttonPresent = false;

	void Start()
	{
		//buttonPressed = false;
	}
	

	void Update()
	{
		if(activeButton == false)
		{
			NewButtonLocation();
		}
	}

	void NewButtonLocation() // Choose a new button to make active
	{
		int newLocation = Random.Range(0,buttonLocation.Length); // Pick number between 1 - 4

		GameObject NewButtonLocation = Instantiate(cannonButton, buttonLocation[newLocation].position, buttonLocation[newLocation].rotation);

		buttonPresent = true;

	}
}

any suggestions guys ???

I think that Instantiate(…) returns an Object so if you want to assign “Instantiate(cannonButton, buttonLocation[newLocation].position, buttonLocation[newLocation].rotation);” to a GameObject you have to cast like this:

GameObject NewButtonLocation = (GameObject) Instantiate(cannonButton, buttonLocation[newLocation].position, buttonLocation[newLocation].rotation);

But I might be wrong.

You should cast to GameObject:

GameObject NewButtonLocation = Instantiate(cannonButton, buttonLocation[newLocation].position, buttonLocation[newLocation].rotation) as GameObject;