UNITY TUTORIAL | SCRIPTING | Data Type

  • Data Type
    • Value : Containing Some Values | if  a Value type changes, only that specific variable is affected
      • int
      • float
      • double
      • boll
      • char
      • Structs(containing one or more other variables)
        • Vector3
        • Quaternion
    • Reference : Containing  a Memory Addresse where the value is stored  | if a Reference type changes, all variable that contain that memory address will also be affected
      • Classes
        • Transform
        • GameObject

WEEK1 | 1-3 |Starting to program| Data Types, Variables, and Constants

9
Computer, everything in Binary

8

6
Power of Binary
7
Power of Binary

 

Data Types, Variables, and Constants

  • everything in a computer is represented in binary
  • the data type of a variable or constant tells how to interpret the bits
  • the data type of a variable or constant tells what we can do (the valid operations for the variable)
1-3-3-Data-Types-Variables-and-Constants
Memory
  • we declare Variables to allocate memory for the
    • (=to get memory space for values we need to store)
    • providing the data type, and the variable name
    • optionally, providing a value
  • we declare Constants to allocate memory for them
    • (=to get memory space for values we need to store)
    • providing the data type, and the constant name
    • necessarily, providing the value
  • the value of a variable can change while running the program
  • the value of a constant can’t change while running the program

 

Integers

  • 0, 42, -11
  • class
    • byte : 8bits
    • short : 16bits
    • int : 32bits
    • long : 64bits
  • not to waste memory, it is important to choose the appropriate class

 


1-3-4-Integer-Data-Types
Input integer | “int.Parse()”

Floating Point Numbers

  • 1.912831631238…..
  • Real Number
    • we don’t have infinite number of bits in a computer
    • we can’t represent the infinite set of real number
      • discrete domain
      • inaccuracy
  • class
    • float : 32bits
    • double:  64bits
1-3-5-Floating-Point-Data-Types
Integer, Float Calculation | Type Cast

 

1-3-5-Floating-Point-Data-Types
Integer, Float Calculation | Type Cast
1-3-5-Floating-Point-Data-Types 2
Attach scripts to gameObject

1-3-5-Floating-Point-Data-Types
Cosine “Math.Cos” | PI “Math.PI”
1-3-5-Floating-Point-Data-Types
Float&Double | TypeCast
1-3-5-Floating-Point-Data-Types 2
change to Degree | “*Math.PI/180”
1-3-5-Floating-Point-Data-Types
Celsius&Fahrenheit | int variable
1-3-5-Floating-Point-Data-Types 2
float variable | double variable
1-3-5-Floating-Point-Data-Types 3
Rounding Error | Float | Double