「毎日Unity」の技術ブログ

開発で役立つ情報を発信する

【UnityC#】対数を得る方法

対数を得る方法を自分用にメモ。

[ 方法 ]

「Mathf.Log(a, b)」で対数を得ることができます。bが底でaが真数です。

[ 使用例 ]

下記はlog2 1024をコンソールに出力するスクリプトです。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ScriptTest : MonoBehaviour
{
    void Start()
    {
        int IntTest = 0;

        IntTest = Mathf.Log(1024, 2);

        Debug.Log(IntTest);
    }
}

log2 1024は10ですね。