|
Java Code - Variables
[Back]
Code:
//You put these on the top of the script, these are the start of it.
var test: int = 1; //Whole Number
var test: float = 1; //Fractional Number
var test: String = "Hello"; //Text
var test: boolean = true; //true or false value
var test: GameObject[ ]; //Game Object
//You use these to add, subtract, multiply, or divide a variable.
test = test +1; //Add
test = test -1; //Subtract
test = test *3; //Multiply
test = test /2; //Divide
//or
test +=1; //Add
test -=1; //Subtract
test *=3; //Multiply
test /=2; //Divide
//How to use Random
var random : float = 0; //Variables
//or
var random : int = 0; //Variables
//first you need a var, then you can use this code to set that var to a random number like 0 to 100
function Start ()
{
random = Random.Range(0, 100);
}
//You use these to change the String variable.
test = "Hi"; //Change String text
//You use these to change the boolean value.
test = false; //Change boolean value to true or false
test = true; //Change boolean value to true or false
//You use these if you need something like, If the variable is equal to, greater than, less than, or not equal to.
//equal to
if ( test == 1 ) {
}
//greater than or equal to
if ( test >= 1 ) {
}
//less than or equal to
if ( test <= 1 ) {
}
//not equal
if (test != 0) {
}
//You use these if you need, if this string value is equal to the text value.
//equal to string value
if ( test == "Hi" ) {
}
//Use this for if you need, if a boolean value true or false.
//equal to true boolean value
if ( test == true ) {
}
//equal to false boolean value
if ( test == false ) {
}
//End"IF", so it don't keep going
Return;
var test: int = 1; //Whole Number
var test: float = 1; //Fractional Number
var test: String = "Hello"; //Text
var test: boolean = true; //true or false value
var test: GameObject[ ]; //Game Object
//You use these to add, subtract, multiply, or divide a variable.
test = test +1; //Add
test = test -1; //Subtract
test = test *3; //Multiply
test = test /2; //Divide
//or
test +=1; //Add
test -=1; //Subtract
test *=3; //Multiply
test /=2; //Divide
//How to use Random
var random : float = 0; //Variables
//or
var random : int = 0; //Variables
//first you need a var, then you can use this code to set that var to a random number like 0 to 100
function Start ()
{
random = Random.Range(0, 100);
}
//You use these to change the String variable.
test = "Hi"; //Change String text
//You use these to change the boolean value.
test = false; //Change boolean value to true or false
test = true; //Change boolean value to true or false
//You use these if you need something like, If the variable is equal to, greater than, less than, or not equal to.
//equal to
if ( test == 1 ) {
}
//greater than or equal to
if ( test >= 1 ) {
}
//less than or equal to
if ( test <= 1 ) {
}
//not equal
if (test != 0) {
}
//You use these if you need, if this string value is equal to the text value.
//equal to string value
if ( test == "Hi" ) {
}
//Use this for if you need, if a boolean value true or false.
//equal to true boolean value
if ( test == true ) {
}
//equal to false boolean value
if ( test == false ) {
}
//End"IF", so it don't keep going
Return;