「毎日Unity」の技術ブログ

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

【UnityC#】bool形からint型に変換する方法

boolからintに変換する方法をメモ。

[ 方法 ]

「Convert.ToInt32(bool)」で変換できます。

[ 使用例 ]

下記はbool型のBoolTestをint型に変換しIntTestに代入しています。

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

public class ScriptTest : MonoBehaviour
{
    void Start()
    {
        bool BoolTest = false;

        int IntTest = Convert.ToInt32(BoolTest);
    }
}

falseだと0でtrueだと1に変換されます。

[ 関連記事 ]

edunity.hatenablog.com