- Home /
Question by
kamuzai1226 · Jan 08, 2015 at 10:04 PM ·
guitoggle
On button toggle, left click returns object name.
How do I create a button, when clicked, allows me to left click on an object in the world and return that object's name?
Comment
Best Answer
Answer by hypnoticmeteor · Jan 08, 2015 at 10:17 PM
using UnityEngine;
using System.Collections;
public class ScreenControl : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(!Input.GetMouseButton(0))
return;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray,out hit)){
print(hit.transform.name);
}
}
}
Make a boolean variable toggle the above code.
This isn't exactly what I was looking for, but it definitely helped me to figure out the problem. Thanks!