I want to convert this on an android by creating a button. This is a flashlight code toggle on and off on FPS. Im working on a thesis proj which is mobile and Im a beginner in Unity. The code works fine. Thanks for response.
using UnityEngine; using System.Collections;
public class FlashlightToggle : MonoBehaviour {
public Light flashlight;
private bool isOn;
public AudioClip flashlightOn;
public AudioClip flashlightOff;
public AudioSource source;
void Start()
{
isOn = true;
}
void Update () {
if (Input.GetKeyDown (KeyCode.F))
{
if (isOn == false) {
flashlight.enabled = true;
isOn = true;
source.PlayOneShot(flashlightOn);
} else if (isOn == true)
{
flashlight.enabled = false;
isOn = false;
source.PlayOneShot(flashlightOff);
}
}
}
}
Answer by ArturoSR · Sep 03, 2016 at 09:24 PM
Hello there.
OK, first you need to work around touch not keys, for debug it's OK, but, for the android you need to read about touch input, check the documentation, even has a very basic example of it, cheers.
but is there any way how to change the control to make it a button? because the Control on my Flashlight toggle is "F" but i want to change it to an android button?
The only button I know it can be used it is the Back, this acts like the Esc in you PC, if you try to use something more like an exterior keypad, probably you need some dynamic library to achieve it, besides, the way to work in android it is generating the UI (some icons used to make the user interacts with your app, you can check the documentation about it).
how can I turn on and turn off the light when the button is pressed? what method should I create like to call it on the click event on the button.
Example : public void GetText(string text) { //Sample Codes }
Im confused sorry for bothering because im a newbie.
Thanks for response :)
Your answer
Follow this Question
Related Questions
my fps vanishes when i tap on my mobile screen 0 Answers
Game slows down when no input is given. 0 Answers
Unity3d 2017.4 android performance 0 Answers