‘If’ Statements

We learnt about if statements in unity in Ant’s lesson. If statements are used when something is conditional in a game.

An example of a situation could be if a character needed to walk on an icy surface in a game where temperature fluctuates, if the ice was cold enough he would walk, if the temperature was higher and the ice was still just water, he would fall through it.

To write an if statement you needed the statement, a condition, and a body.

e.g. if(number==1){

This code would work in a coin toss to say out of 1 and 2, if the number was 1, you would get heads as a result.

To get tails you could write the same code and change ‘1’ to ‘2’ and ‘Heads’ to ‘Tails’.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s