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

UNITY TUTORIAL | SCRIPTING | Time.deltaTime

 

1
“PlayerControl” Script from Space Shooter 2D
  • when trying to move Player,  add Time.deltaTime to make the movement soft
  • it makes action in Update(), independent from frame and dependent on time
1-1
Moving Player Smoothly

 

2
“PlayerControl” Script from Space Shooter 2D
  • let’s try to remove Time.deltaTime

 

2-1
Moving Player drastically

 

 

ezgif.com-video-to-gif (1)
Time.deltaTime

UNITY TUTORIAL | SCRIPTING | GetComponent()

Unity Tutorial | Scripting |Getcomponent()

 

Script itself is a custom game component

also, in a script, we can modify other components such as “RigidBody”, “Collider”, or even another “Script”

to modify components in a script we need variables as a bowl for the component and we need to put the component in the variable by using “GetComponent()”

 

2
“PlayerControl” Script | Creating a Varaible
  • Create a variable “GameManager” as a bowl to bring and use “Gamemanger” script or class in this script
3
“GameManager” Script | Custom Function
  • there is a custom function, “SetGameManagerState()” in “GameManager” script or calss
4
“PlayerControl” Script | GetComponent()
  • put the class in the variable by using “GetComponent()”
  • after that, we can use the functionality of “GameManager” class in this script

 

5
“Player” GameObject | Inspector | Audio Source
  • in “Player” GameObject,
    • “PlayerControl” scrip & “Audio Source” are attached
    • we want to use  “Audio Source” in “PlayerControl” Script
6
“PlayerControl” Script | GetComponent()
  • In “PlayerControl” Script,
    • create a variable as a bowl for “Audiosource”
    • put the class by using “GetComponent()”
    • use “AudioSource”