Small Wings Big Dreams (Unity 2D, C#)
This section contains examples of features and their snippets of their code implementation.
Enemy Behaviour
The Code snippet below shows the setup for basic enemy movement, which includes, movement, and the appropriate checks to make sure no bugs occur.
The AI gets it's position to move to and from by a public variable defined in the script, but is accessible in the Unity Editor, where an object is used to assign two positions that the enemy should path between.
.png)
PosOne and PosTwo are the game objects which are assigned to the public enemy specific positions
.png)
.png)
Position One
Position Two
This snippet shows the movement functionality which is called in void Update() which is called every frame.
.png)
The snippet below shows the enemy's collision functionality, which checks any collision between the enemy and player and performs accordingly, dealing damage to the player unless the player collides with the enemy from above in which case the enemy receives damage and the ApplyDamage function is called.
.png)