Galaxy Shooter 2D — Player Start Position

Sidchou
2 min readOct 8, 2021

--

Objective: initialize start position for the player.

Create a New C# Script

Create a script folder and add a c# script in there by right click > Create> C# script. Name the file as Player when it first created *if renamed afterward, you will need to adjust the class name afterward.

create new c# script

C#

Double click on the script and open it with Visual Studio Code, or any preferred text editor.

new C# script

a. Name Space -library included.

b. Class Name -Make sure the class name match the file name.

c. Void Start -function called once when the game start.

d. Void Loop -function that repeat every frames (~60fps).

Change Default Scripts Editor

To change the default IDE, go to edit>preference>external tools>external script editor

change default IDE

Set player starting position

I am going to use void start to set the player starting position to (0,0,0) so it will snap to the center in the beginning of the game

transform.position = new Vector3 (0,0,0);

Now when I press the play button for test play, the cube should snap to the middle

--

--

Sidchou

An Unity Developer who loves to create interactive and immersive experiences.