23 Oct
23Oct

Prevent screen dimming / device from sleeping (Stop mobile screens turning off)

using UnityEngine;

public class Example : MonoBehaviour 
{
  void Start() 
  {
    // Disable screen dimming
    Screen.sleepTimeout = SleepTimeout.NeverSleep;
     
    // To revert it back, use this:
    // Screen.sleepTimeout = SleepTimeout.SystemSetting;
  } 
}

Link / Source: Unity Documentation


Get class / method name of script

using UnityEngine;
using System.Reflection;

public class Example : MonoBehaviour 
{
  void Start()
  {
    print(this.GetType().ToString());    print(this.gameObject.Getcomponent<MonoBehaviour>());    print(MethodBase.GetCurrentMethod().Name);  }
}

Link / Source: Unity Forums

Comments
* The email will not be published on the website.