Hi All,
I am about to develop a calculator. My artist given me a calculator object, in that all the buttons are separate objects and calculator screen also separate. How do I write the code for it for accessing all the buttons with over the screen.can I use GUI text for accessing calculator.? If so let me know the procedure behind it.
Ok I guess your question is not about making calculation but about how to get the pressed button.
Two ways that I know.
First use GUI.Button. You would have to create a GUIStyle for each button or a GUISkin for the whole thing , and pass the corresponding style/skin index.
GUIStyle button1 = new GUIStyle();
GUIStyle button2 = new GUIStyle();
public Texture2D texture1;
public Texture2D texture2;
void Start(){
button1.normal.background = texture1;
button2.normal.background = texture2;
}
void OnGUI(){
if(GUI.Button(positionRect1,"",style1)){}
if(GUI.Button(positionRect2,"",style2)){}
}
The other way is to use planes to which you pass the texture and then you use a basic raycast and check. You would manually place them in the environment.
RaycastHit hit;
public Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 100)){
if(hit.collider.tag == "Button1"){}
if(hit.collider.tag == "Button2"){}
}