Acem Gaming
  • Home
  • Tutorials
    • Unity Beginner Game Design >
      • Game Design Intro
      • Unity Environment
      • Intro to Visuals
      • Intro to Coding
      • Intro to UI Design
      • Intro to Physics
      • Intro to Materials, Textures, and Lighting
    • Unity C# Tutorials >
      • Beginner >
        • Introduction
        • Variables
        • Operators
        • Conditional Statements
        • Loops
        • Methods
        • Arrays
        • Structures
        • Classes
        • Enumerations
      • Intermediate >
        • Type Conversion
        • Switches
        • Inheritance
        • Encapsulation
        • Polymorphism
        • Static
        • Properties
        • Interfaces
        • Lists
        • Dictionaries
      • Advanced >
        • Delegates
        • Events
        • File IO
        • Stacks
      • DesignPatterns >
        • Proxy
        • BehavioralPatterns >
          • ChainOfResponsibility
    • Unity Oculus Rift Tutorials >
      • Set-Up
      • Camera Set-up
      • Object Interaction
    • Unity Odds & Ends >
      • Unity UI Tutorial : Healthbar Part 1
      • Unity UI Tutorial: Healthbar Part 2
      • Unity Scriptable Object Tutorial
      • Vector Math
      • Lerp
      • Basics of Motion Physics
      • Unity Physics Basics
      • Clamping Values
      • Linear Physics Movement
    • Legacy Tutorials
  • Game Demos
    • WebGLTest
  • Blog

Part 2 - Variables

Part 2 of this C# tutorial series is all about variables.
Overview
Variables are keywords that denote storage space for a program to store various data.  The amount of space that is given depends on the type of the variable.  
The most basic form a variable declaration is shown below:
<data type> <variable list>

    
If you want to get fancy you can add an additional access modifier.  Access modifiers denote who has access to a variable/function, but we will cover that in detail in another tutorial.
<access modifier> <data type> <variable list>

    
There are two main types of variables; Value and Reference types.
Value Types
Value type variables can be assigned a value directly.  When you declare these variables, the system allocates the appropriate amount of memory for them.  The table below illustrates many of the value types available in C#.
Picture
Reference Types
Reference types do not contain data directly, they simply give a reference, or location, to data.  One may ask why you would want references to variables rather than all variables being value typed.  The reason is that if the data inside a reference variable changes, the reference variable automatically reflects those changes.  This makes more sense as you start to delve into complex data types.
A common example is creating an instance of a class, and then setting that instance to a known instance of the class.  By doing that, you have told the second instance of the class to point to the original.

Example of a reference type: 
string name = "Drew"
Example
Look at the following picture at the right.  Come up with different attributes that you could store as variables for the object.
Examples:
Color of the gear
Number of spokes on the gear
Background Color


Picture
Video

Services

Service One
Service Two
Service Three

Company

About
The Company
Menu

Support

Contact
FAQ
Terms of Use
© COPYRIGHT 2015. ALL RIGHTS RESERVED.
  • Home
  • Tutorials
    • Unity Beginner Game Design >
      • Game Design Intro
      • Unity Environment
      • Intro to Visuals
      • Intro to Coding
      • Intro to UI Design
      • Intro to Physics
      • Intro to Materials, Textures, and Lighting
    • Unity C# Tutorials >
      • Beginner >
        • Introduction
        • Variables
        • Operators
        • Conditional Statements
        • Loops
        • Methods
        • Arrays
        • Structures
        • Classes
        • Enumerations
      • Intermediate >
        • Type Conversion
        • Switches
        • Inheritance
        • Encapsulation
        • Polymorphism
        • Static
        • Properties
        • Interfaces
        • Lists
        • Dictionaries
      • Advanced >
        • Delegates
        • Events
        • File IO
        • Stacks
      • DesignPatterns >
        • Proxy
        • BehavioralPatterns >
          • ChainOfResponsibility
    • Unity Oculus Rift Tutorials >
      • Set-Up
      • Camera Set-up
      • Object Interaction
    • Unity Odds & Ends >
      • Unity UI Tutorial : Healthbar Part 1
      • Unity UI Tutorial: Healthbar Part 2
      • Unity Scriptable Object Tutorial
      • Vector Math
      • Lerp
      • Basics of Motion Physics
      • Unity Physics Basics
      • Clamping Values
      • Linear Physics Movement
    • Legacy Tutorials
  • Game Demos
    • WebGLTest
  • Blog