UNITY | PROJECT | SPACE SHOOTER 2D | 12. Accelerometer​ Input & Shoot Virtual Button

1.1
Changing Build Target to IOS
1.2
Changing Resolution
1.3
Connecting “Unity Remote5” on iPhone

 

2.1
“Player Control” Script
  • Set the input sources for x&y from iPhone’s Accelerometer
  • Create a Vector2 from the 2 x, y inputs
  • Limit the vector(direction) into 1 by using “Vector2.sqrMagnitude”
    • Think about the Lenth of Vector
    • Relate this with the Pythagorean theorem

 

2.2
Inputs from Accelerometer working but…..
2.3
“PlayerControl” Script
  • Subtract the initial value of Y input from the whole Y input to prevent the player ship from going down when grabbing the phone downwards
2.4.1
Increasing the speed
2.4
Inputs from Accelerometer working
3.1
Importing Shooting Button
  • Create “UI Button”
  • Add “Shoot Button” image to “Source Image” of “UI Button”
  • Set the anchor to “Right-Bottom”
3.2
“Player Control” Script
  • Create a Function, “Shoot()” to make the button work
    • move the code for shooting in “Update()” to “Shoot()”
4
UI Button | On Click
  • Set the action when the button is clicked
    • Add “Player” to “On Click()” and Set “Shoot()” function
5.1
“On Click()”
12. Accelerometer Input - Shoot Virtual Button
“GameManager” Script
  • Get the reference for ShootButton
  • When Case “GamePlay”
    • Set “shootButton” active
  • When Case “GameOver”
    • Set “shootButton” disactive
6.2
“ShootButton” Disactive in the Inspector
6.3
“Shoot Button” Working