Code (csharp): void BuildingCallout() { RaycastHit hit = new RaycastHit(); Ray ray = new Ray(); ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Input.GetMouseButtonDown (0)) //Returns true during the frame the user touches the object { Debug.Log("mouse down"); if (Physics.Raycast (ray, out hit)) { Debug.Log("pew pew"); if (hit.collider.gameObject.name.Equals("BrooksCallOut")) { Debug.Log("go brooks"); BrooksCallOut.gameObject.SendMessage("gotoBrooks"); } } } else { } } So here's my code. Its pretty strait foward, a raycast looks to the collider and if it hits a specific gameObject, it executes the function "gotoBrooks". I don't get any errors when I run the script but in the player, not a single one of the debug logs print. Does anyone have any idea what could be going on?
Where do you call BuildingCallout from? Update would seem to be the obvious place, but you don't specify. Additionally, some tips: Code (csharp): Ray ray = new Ray(); ray = Camera.main.ScreenPointToRay(Input.mousePosition); can be collapsed into Code (csharp): Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); and if you move Code (csharp): RaycastHit hit = new RaycastHit(); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); inside "if (Input.GetMouseButtonDown(0))" you won't have to create them every frame unless the user clicks the mouse.
So looking a bit further into it, it seems that even though I am defining the gameObject, Code (csharp): public GameObject BrooksCallOut; and the object is connected in the inspector, its not being recognized.
I'm not sure I entirely understand what you mean or how you have things set up. Is "BrooksCallOut" an instance variable? If so, consider changing it to "brooksCallOut" (by convention, variables start with lowercase and classes or functions start with uppercase). It also appears you're never assigning it anywhere when you get your hit. Try Code (csharp): if (hit.collider.gameObject.name.Equals("BrooksCallOut")) { Debug.Log("go brooks"); BrooksCallOut = hit.collider.gameObject; BrooksCallOut.SendMessage("gotoBrooks"); }
When using "out" methods, you shouldn't initialize the variable you're assigning to. That is: Code (csharp): RaycastHit hit = new RaycastHit(); change to: RaycastHit hit; It may not be the culprit, but this is the proper procedure.
Well the problem seems to have been some mystical gnome trickery. I deleted the gameObjects, reimported them, and reassigned all the script/inspector links and now it works. Thank you all for your help.