can't load a prefab as my GameObject variable

I need to change the projectile type as user clicks a button.

I have used this script but it cannot assign my prefab to “projectile” variable.
I even tried Resources.Load() and GameObject.FindWithTag() help please!

if (Input.GetButtonDown ("Fire2")) {   	
	if (projectile.transform.name == "cannonball") {
		projectile = GameObject.Find("rocket");  				
 	}
 
	else {
		projectile = GameObject.Find("cannonball");
	}

	print(projectile.transform.name+ " is selected!");
}

Try
AssetDatabase.LoadAssetAtPath(assetRelativePath, typeof(GameObject)) as GameObject;

I believe that .find only works on objects in the hierarchy. So if the prefab doesn’t exist in the world it won’t be able to find that object.

I hope someone will verify that though.

An easy alternative is to create variables for each projectile type that weapon can use.

var projectile1 : GameObject;
var projectile2 : GameObject;

And drag the prefabs in in the inspector. Then change the projectile that way.