- Home /
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;
}
}
}
}
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.
Ok I see but, I don't understand how to make it detect the buttonZero. How would I do that??
$$anonymous$$aybe, if (hitInfo.transform.gameObject == buttonZero)
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.
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
Answer by Atonez · Sep 23, 2014 at 03:23 AM
Have you tried changing the input. Edit/Project Settings/Input.
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
Follow this Question
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