Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity c# bool to int conversion

using System.Collections;
using UnityEngine;

public class SampleClass : MonoBehaviour
{
	//Example
	private int sampleInteger = 1;
    private bool sampleBoolean = false;
	private void SampleMethod(){
    	sampleInteger = BoolToInt(sampleBoolean);	//=> false becomes 0
        sampleBoolean = IntToBool(sampleInteger);	//=> 1 becomes true
    }

	//Methods for conversion between Integer and Boolean types
    private bool IntToBool(int val){
        if (val == 1)
            return true;
        return false;
    }
    private int BoolToInt(bool val){
        if (val)
            return 1;
        return 0;
    }
}
 
PREVIOUS NEXT
Tagged: #unity #bool #int #conversion
ADD COMMENT
Topic
Name
1+5 =