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 /
  • Help Room /
avatar image
0
Question by kevinamoin23 · Sep 03, 2016 at 08:17 PM · androidfpsflashlight

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);
         }
     }
 
 }

}

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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.

Comment
Add comment · Show 6 · 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 kevinamoin23 · Sep 04, 2016 at 07:33 AM 0
Share

thanks sir :) godbless

avatar image kevinamoin23 · Sep 04, 2016 at 09:06 AM 0
Share

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?

avatar image ArturoSR kevinamoin23 · Sep 05, 2016 at 12:37 AM 0
Share

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).

avatar image kevinamoin23 ArturoSR · Sep 05, 2016 at 01:35 PM 0
Share

Ok sir thanks for the response :D Godbless

Show more comments
avatar image kevinamoin23 · Sep 06, 2016 at 05:42 AM 0
Share

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

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

98 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

How can I set the correct answer on the question when the user touch the button. I prefer c#. Please help Im stuck :( 0 Answers

FPS drop down after some time (Android) 1 Answer


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