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 GhostDre · Sep 22, 2014 at 08:56 PM · c#buttonsnumbers

Remote KeyPad with Buttons

Hi everyone I'm in a bit of a pickle. I'm trying to make a remote security keypad in unity. So basically it displays a gameObejct with 10 different buttons that represents 0-9 digits. Once push the button will turn red, which will symbolize that it is pushed. I'm having trouble setting this up can some one help please? I started but then I don't know where to go. And yes it is in CSharp.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 public class KeyPad : MonoBehaviour
 {
    public float distance = 25.0f;
    public GameObject buttonZero;//Number Zero Button for the KeyPad
 
    void Update () 
    {
     if(Input.GetMouseButtonDown(0))
     {
         Ray rayOrigin = Camera.main.ScreenPointToRay(Input.mousePosition); 
         RaycastHit hitInfo; 
 
         if (Physics.Raycast(rayOrigin, out hitInfo, distance))
         {
             Debug.Log ("0");//Just to let me know its hitting the object
 
             if (hitInfo.rigidbody != null) 
                 hitInfo.transform.buttonZero.renderer.material.color = Color.red;
 
         }
     }
    }
 }
Comment
Add comment · Show 8
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 Graham-Dunnett ♦♦ · Sep 22, 2014 at 08:57 PM 1
Share

What's not working? Presumably line 21 doesn't compile? You probably need to detect what's been clicked on, and then, if it's a button, change it's colour.

avatar image GhostDre · Sep 23, 2014 at 03:21 PM 0
Share

Ok I see but, I don't understand how to make it detect the buttonZero. How would I do that??

avatar image roojerry · Sep 23, 2014 at 03:29 PM 0
Share

$$anonymous$$aybe, if (hitInfo.transform.gameObject == buttonZero)

avatar image GhostDre · Sep 23, 2014 at 06:12 PM 0
Share

So your saying if I did this:

 if (hitInfo.transform.gameObject == buttonZero) 
 {
             hitInfo.transform.buttonZero.renderer.material.color = Color.red;
 }

It still cause an error. Unless I'm missing something.

avatar image roojerry · Sep 23, 2014 at 06:23 PM 0
Share

yes, however this:

hitInfo.transform.buttonZero.renderer.material.color

makes no sense. You are trying to get the class variable buttonZero from the transform of the object you hit with the ray. Shorten it to:

 hitInfo.transform.renderer.material.color

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Atonez · Sep 23, 2014 at 03:23 AM

Have you tried changing the input. Edit/Project Settings/Input.

Comment
Add comment · Show 1 · 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 GhostDre · Sep 23, 2014 at 03:23 PM 0
Share

Its not that type of button. Its an actual security keypad button that I'm working on. You know in order to lock your house you need to put in a code on your alarm keypad to secure it.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to connect the strings i get ftom pressing buttons 1 Answer

need help with buttons!! 1 Answer

How to get sound to play and pause with the new UI 1 Answer

Bring class variable into other class 1 Answer

Using Buttons to write numbers 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