Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Ramss · May 18, 2013 at 05:22 AM · guiscreenaccessingwith

Implementation of a calculator with a given object(calculator)

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · May 18, 2013 at 06:05 AM 0
Share

Doing a calculator is can be a complex problem depending on how far you want to take it and how closely you want to mimic a "real" calculator. Here is a question that talks a bit about a calculator:

http://answers.unity3d.com/questions/407297/simple-calculator-for-kid-math-app.html

Note @fafase code might give you a starting point. He is using GUI.Button() with strings. You would be using GUI.Button() with your textures.

Given the scope of this problem (many separate technical issues that can be solved in a number of ways), the Unity Forum is likely a better place for this question.

avatar image Ramss · May 18, 2013 at 08:12 AM 0
Share

I have already gone through this ..This is entirely different from my question.I have an obj. I have to access the screen obj in the calculator obj. for every hit w.r.t to button the corresponding value has to be displayed. once I get it done I'll write the code for proper working of the calculator.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by fafase · May 18, 2013 at 08:41 AM

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"){}
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ramss · May 20, 2013 at 09:10 AM 0
Share

Thank u for giving me a direction. But please find this attachment.In this I put my calculator object image. For this buttons are objects and calculator screen also another object. I added box colliders to all the buttons. Now I tagged all buttons.though the above code is not working.

2)after I get access to the buttons, how can I use GUI text to make the text to be displayed on the calculator screen.

calsi.png (201.7 kB)
avatar image Bunny83 · May 20, 2013 at 09:38 AM 1
Share

You just place a Text$$anonymous$$esh over your diplay.

Seriously, if you ask such a question you either started using Unity 23.4 $$anonymous$$utes ago and / or you're just very lazy to actually look through the things Unity offers. For any task there are multiple ways to get the job done. First you should be clear about what you need. The second step is to look out what functions / components / features in Unity can be used to implement what you want.

If you're new to Unity, just take a look at this page. There's a complete list of all classes that comes with Unity. You should invest some time and look through the list. Almost all classnames give a good hint what the class is good for.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to access a screen(separate obj in my app). 1 Answer

Android Button Screen 1 Answer

How can I get a UI Panel's size in relation to the screen size? 1 Answer

Developing a Dynamic GUI 1 Answer

GUI adapting to screen resolution? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges