- 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
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
Best Answer
Answer by DRIVER1ksa · Jun 16, 2016 at 10:10 AM
today the asset dev has update he script
thanx
closed
Follow this Question
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