Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

integer to boolean conversion in unity C#

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: #integer #boolean #conversion #unity
ADD COMMENT
Topic
Name
3+8 =