Answers for "unity get screen width"

C#
5

unity get screen width

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Example : MonoBehaviour
{
    void Start()
    {
        //Output the current screen window width in the console
        Debug.Log("Screen Width : " + Screen.width);
    }
}
Posted by: Guest on May-08-2021
2

unity get screen size

// Static Properties:
brightness	        // The current brightness of the screen.
currentResolution	// The current screen resolution (Read Only).
fullScreen	        // Is the game running full-screen?
height	       // The current height of the screen window in pixels (Read Only).
resolutions	// All full-screen resolutions supported by the monitor (Read Only).
width	        // The current width of the screen window in pixels (Read Only).
  
// Example: currentResolution
using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
        print(Screen.currentResolution);
    }
}

// Example: fullScreen
using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
        // Toggle fullscreen
        Screen.fullScreen = !Screen.fullScreen;
    }
}

// Example: height
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
        //Output the current screen window height in the console
        Debug.Log("Screen Height : " + Screen.height);
    }
}

// Exmaple: resolutions
using UnityEngine;

public class ExampleScript : MonoBehaviour
{
    void Start()
    {
        Resolution[] resolutions = Screen.resolutions;

        // Print the resolutions
        foreach (var res in resolutions)
        {
            Debug.Log(res.width + "x" + res.height + " : " + res.refreshRate);
        }
    }
}

// Example: width
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
        //Output the current screen window width in the console
        Debug.Log("Screen Width : " + Screen.width);
    }
}
Posted by: Guest on August-17-2021

C# Answers by Framework

Browse Popular Code Answers by Language