Tut78: Extra Exercise. [Basic]

Here’s a basic exercise designed to test your understanding of functions in C#.

Exercise:
In Petey’s BurgZergArcade tutorial episode #78: Day Night Cycle part 7, take the if statement and turn it into a function with an appropriate call in the Start() function.

void Start() {
if(GetComponent() != null)
givesLight = true;
}

Hint:
Read the rest of this entry »

Advertisements

Programming Error: Cannot implicitly convert type `float’ to `int’.

error CS0266: Cannot implicitly convert type `float' to `int'. An explicit conversion exists (are you missing a cast?)

Explanation:
This often happens when ints are used in an equation that would yield a non-int, such as a decimal (float). In the example, 100/3 is 33.33333, which is being stored in an int. An int cannot store decimals, you need a float or double for that.

Example:
int var = 100/3;

Solution:
Read the rest of this entry »