Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
9
Question by Richard 3 · Feb 04, 2011 at 11:41 AM · androidscreenoff

Stop Mobile screens turning off

How do I stop the screen turning off on an android. I can stop the screen going dim but not to stop turning it off. My game uses the accelerometer.

Thanks

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

6 Replies

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

Answer by Macarse · May 02, 2012 at 07:36 PM

You should use:

 Screen.sleepTimeout = SleepTimeout.NeverSleep;
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 Arrow · Feb 20, 2013 at 03:29 PM 1
Share

I don't have enough user points/karma/whatever to upvote, yet, but this is the real right answer. .NeverSleep didn't used to exist, but it does now, and you should use it.

avatar image p.hufnagl · Feb 06, 2014 at 08:45 AM 1
Share

I have! +1! I got you covered :)

avatar image stuartb · Apr 09, 2014 at 07:29 AM 0
Share

It's not working for me, should I put it in Update() or is Start() fine?

avatar image CarlGammaSagan · Jul 15, 2015 at 11:32 PM 0
Share

Yea, as asked by stuartb, where should we put this line of code?

avatar image chelder · Sep 10, 2015 at 09:07 AM 0
Share

Within a Start function because we need to execute it just once (source: http://answers.unity3d.com/questions/348637/how-to-make-the-android-screen-always-turns-on.html)

Show more comments
avatar image
3

Answer by Richard 3 · Feb 04, 2011 at 01:37 PM

this script does both

iPhoneSettings.screenCanDarken = false;

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
avatar image
2

Answer by franklynw · Jan 27, 2012 at 12:30 PM

The iPhoneSettings.screenCanDarken is deprecated - it's now

 Screen.sleepTimeout = 0f;

0 is never darken, other values in seconds - docs here

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
avatar image
2

Answer by Grixen · Feb 16, 2016 at 01:01 PM

My Asus ignoring or forget sigle command and stoutly get screen twice darker after a minute. In some little expeiments ive got a solution:

     Screen.sleepTimeout = (int)0f;
     Screen.sleepTimeout = SleepTimeout.NeverSleep;

in void Update () section, somehow wakes it nonsop.

Comment
Add comment · Show 2 · 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 NeatWolf · Jan 06, 2017 at 11:33 AM 0
Share

Duh, so this means that we should always force this value?

Does this work on iOS and Android or do I need to use iPhoneSettings.screenCanDarken?

Is it required to do the double assignment? Why are you using (int)0f ins$$anonymous$$d of just 0?

I think (int)SleepTimeout.NeverSleep equals to 0 as well.

But probably you're showing two alternative methods here, I'm not sure. Could you please explain? Thank you :)

avatar image sherpadude · Mar 12, 2020 at 02:15 PM 0
Share

Thanks for your answer, have same issue with Xiaomi phones. Using just NeverSleep line does not prevent dim$$anonymous$$g.

avatar image
0

Answer by gokturk1 · Jul 19, 2020 at 11:51 PM

     //     Prevent screen dimming.
     public const int NeverSleep = -1;
     //
    
     //     Set the sleep timeout to whatever the user has specified in the system settings.
     public const int SystemSetting = -2;

I found this on source code so if you want make it never sleep you should use -1 instead of 0 and -2 for system default value if you changed it to any different value. But I recomend Screen.sleepTimeout = SleepTimeout.NeverSleep; as Macarse said. You can hover over neverSleep to see -1 value by yourself . Just wanted to make it clear 0 is not the true answer for never sleep it is -1

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
  • 1
  • 2
  • ›

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

13 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

Related Questions

How do you clamp a camera by mobile width? 2 Answers

How do I rotate an object on one axis to face android touch? 0 Answers

White screen before Splash screen change to black 0 Answers

Flickering screen after Android device lock/unlock,Flickering screen after device lock 0 Answers

How do I set an Android applications resolution? 4 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