C# Need some help with mouse interactions

I’m having trouble figuring out how to interact with an instantiated game object that I’ve got drawn on the screen. I’m trying to build an independent GUI manager script that’s supposed to allow me to interact with a game object and rename it, modifiy it’s other details, etc… when selected by a mouse. In the past I used to have these types of functions integrated into the script attached to the prefab but I’m trying to optimist my game now by having a single manager handle all the interaction functions.

I’ve looked around on the web and can’t actually find any tutorials explaining how I can retrieve a gameobject from a mouse click. Can anyone point me in the right direction as to how I’d snag the gameobject reference from a mouse click? Thanks

this should help :slight_smile:

Just talks about raycast and physics applications, doesn’t exactly help me get a GO out of a clicked object. I’m not using a physics system.

Well if you can’t figure out how to do it with what I linked then you need to go back to basics. The answer is right there in the code.

How about …

using UnityEngine;
using System.Collections;
public class GUIManager : MonoBehaviour {
// Use this for initialization
GameObject testGO;
void Start () {

}

// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown (0)) {
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit))
testGO = hit.transform.gameObject;
 Tile tTile = testGO.GetComponent<Tile>();
 print ("And the winner is: " + tTile.GetName());
}
}
}

ok, so is there a better way to do this? I want to be able to retrieve details from the script attached to the GO prefab, but this is the best I could come up with.