Legacy Documentation: Version 5.4
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Mathf.ClosestPowerOfTwo

public static int ClosestPowerOfTwo(int value);

Parameters

Description

Returns the closest power of two value.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Example() { Debug.Log(Mathf.ClosestPowerOfTwo(7)); Debug.Log(Mathf.ClosestPowerOfTwo(19)); } }