Simple script problem

Hi,I’m or I was,I don’t know a javascript scripter,but I think nice to use c#,I learned c# syntax faster but I’m having many problems to use it with unity.That’s my problem:
I got a code that create a ball when F1 is pressed:
In C#:

using UnityEngine;
using System.Collections;


public class Shot : MonoBehaviour {
 public GameObject bola;
	
	void Update () {
	if(Input.GetKeyDown("F1"))
	{
 GameObject ball=GameObject.Instantiate(bola);
	}
	
	}
}

But this code doesn’t works.That’s the error message:

 Cannot implicitly convert type `UnityEngine.Object' to `UnityEngine.GameObject'. An explicit conversion exists (are you missing a cast?)

I translate it to js:

var bola:GameObject;
function Update () {

if(Input.GetButtonDown("F1"))
	{
var ball=Instantiate(bola,transform.position,transform.rotation);
	}
}

And works,but c# with the same things fails:(

using UnityEngine;
using System.Collections;


public class Shot : MonoBehaviour {
 public GameObject bola;
	
	void Update () {
	if(Input.GetKeyDown("F1"))
	{
 GameObject ball=GameObject.Instantiate(bola) as GameObject;
	}
	
	}
}

To fix this problem in c#, you need to cast your Instantiate call to a GameObject. Instantiate doesn’t return a GameObject, it returns an Object. Since you don’t have your ball variable set to be a GameObject in your JS code, it doesn’t throw an error because it just makes “ball” an Object. You can fix it in c# like this:

using UnityEngine;
using System.Collections;


public class Shot : MonoBehaviour {
public GameObject bola;
	
	void Update () {
	if(Input.GetKeyDown("F1"))
	{
		GameObject ball = [COLOR="red"](GameObject)[/COLOR]GameObject.Instantiate(bola,transform.position,transform.rotation);
	}
	
	}
}

Yes it works:smile:
Thank very much:)