Hi all. Having some problems with Instantiating an object into the game world. Nothing fancy. Ultimately, I would like to click on a GUI Button and that will instantiate a node object that attaches to the mouse pointer to create a simple "select and drop" mechanic.
But need to learn how to walk first before running... I made a prefab of a cylinder called "Node". I have some script attached to my Main Camera to handle the game's GUI. All I want at this point is to click on a button to spawn an instance of the Node prefab into the world. Here's some code:
public class ElementsHUD : MonoBehaviour {
public GameObject Node;
// Display buttons
void OnGUI() {
GUILayout.BeginArea (new Rect (Screen.width/2 - 200, Screen.height/2 + 100, 300, 300));
GUILayout.Box (textOutput);
GUILayout.EndArea ();
if (GUI.Button(new Rect(100, 300, 100, 20), new GUIContent("Node 1")))
{
GameObject objNode = Instantiate(Node, transform.position, transform.rotation);
}
My main concern is how do I get the script to reference the cylinder prefab I have sitting in the Hierarchy? Secondary concern is how to instantiate this cylinder at a specific vector? Sorry this seems like a very basic question but would appreciate any pointers.
Thank you!