Mathf.IsPowerOfTwo 是否2的幂

static function IsPowerOfTwo (value : int) : bool

Description描述

Returns true if the value is power of two.

如果该值是2的幂,返回true。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void Awake() {
		Debug.Log(Mathf.IsPowerOfTwo(7));
		Debug.Log(Mathf.IsPowerOfTwo(32));
	}
}
// prints false
Debug.Log(Mathf.IsPowerOfTwo(7));

// prints true
Debug.Log(Mathf.IsPowerOfTwo(32));
Page last updated: 2011-4-16