Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Jun 16, 2016 at 09:54 AM by DRIVER1ksa for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DRIVER1ksa · Jun 15, 2016 at 06:17 AM · unity 5uigamekeyboardkeycode

KeyCode to Ui ? for mobile

i'm stuck on this script the whol script use keyboard "H" and i don't how exactly to convert it to Ui touch for android

 using UnityEngine;
 using System.Collections;
 
 public class PoliceLights : MonoBehaviour {
 
 
 
     public Light[] RedLights;
     public Light[] BlueLights;
 
     public float time = 20;
 
     private float timer=0.0f;
     private int lightNum = 0;
 
     enum LightsMode {Active=1 , Inactive=2}
     private LightsMode lightsMode = LightsMode.Inactive;
 
     void Update () {
 
 
 
 
         if (Input.GetKeyDown(KeyCode.H) && lightsMode == LightsMode.Inactive)
         {
             lightsMode = LightsMode.Active;
 
         }
         else if (Input.GetKeyDown(KeyCode.H) && lightsMode == LightsMode.Active)
         {
             lightsMode = LightsMode.Inactive;
         }
 
 
 
 
 
         if (lightsMode == LightsMode.Active)
         {
             timer = Mathf.MoveTowards(timer, 0.0f, Time.deltaTime * time);
 
 
 
             GetComponent<AudioSource>().enabled = true;
 
             if (timer == 0)
             {
                 lightNum++;
                 if (lightNum > 12) { lightNum = 1; }
                 timer = 1.0f;
             }
 
 
 
 
 
             if (lightNum == 1 || lightNum == 3)
             {
 
                 foreach (Light RedLight in RedLights)
                 {
                     RedLight.enabled = true;
                 }
 
                 foreach (Light BlueLight in BlueLights)
                 {
                     BlueLight.enabled = false;
                 }
             }
 
             if (lightNum == 5 || lightNum == 7)
             {
 
                 foreach (Light BlueLight in BlueLights)
                 {
                     BlueLight.enabled = true;
                 }
 
                 foreach (Light RedLight in RedLights)
                 {
                     RedLight.enabled = false;
                 }
             }
 
 
             if (lightNum == 2 || lightNum == 4 || lightNum == 6 || lightNum == 8)
             {
 
                 foreach (Light BlueLight in BlueLights)
                 {
                     BlueLight.enabled = false;
                 }
 
                 foreach (Light RedLight in RedLights)
                 {
                     RedLight.enabled = false;
                 }
             }
 
         }
         else
         {
             GetComponent<AudioSource>().enabled = false;
 
             foreach (Light BlueLight in BlueLights)
             {
                 BlueLight.enabled = false;
             }
 
             foreach (Light RedLight in RedLights)
             {
                 RedLight.enabled = false;
             }
 
 
         }
 
 
 
     }
 
 
 
 }




i try this solution but didn't work for me

 using UnityEngine;
 using UnityEngine.UI;
 
 [RequireComponent(typeof(Button))]
 public class KeyButton : MonoBehaviour {
 
     public KeyCode key;
 
     public Button MyButton {get; private set;}
 
     void Awake() {
         MyButton = GetComponent<Button>();
     }
 
     // Update is called once per frame
     void Update () {
         if (Input.GetKeyDown(key)) {
             MyButton.onClick.Invoke();
         }
     }
 }

i use unity 5.3

any idea ?

Comment
Add comment · Show 1
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 KuR5 · Jun 15, 2016 at 06:48 AM 0
Share

Hey, here is the answer of your question.

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by DRIVER1ksa · Jun 16, 2016 at 10:10 AM

today the asset dev has update he script

thanx

closed

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Moving between UI Buttons Using Keyboard Arrows 0 Answers

Panel isn't opening after hitting the tab key, and its not even saying I pressed the key? 0 Answers

i can assign all keys but the shift any ideas 4 Answers

Disable on screen keyboard for mobile phones 1 Answer

How can I collect playerprefs values? 0 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