Monday, 30 November 2020

Activity 8: Game Level Feature

 

          This blog contains information about next level features using Unity 2D. 

First, We need Following Image Objects : Player, Meteor(Enemy), Star(Ally), Button and Background(optional). In my part, I created these object using Adobe Illustrator and some on internet.



Then I need 4 Scene  in the Asset; Level01,Level02,Level03 and MainMenu. There I proceed to File to Build Settings to drag and drop this Scene, we should see like this. 

Lets start setting up our main menu, double click main menu from Assets. I need 3 Buttons for my level selection and a Reset button.

There I put text from ui for Main Menu and Select Level title, then for the buttons I used the button image I have so we see like this. You can setup the Text in the child of the button.




   Scene Button 

     Reset Button

Here in the Components we setup Onlick Event with our level buttons and to reset.  I also have MainMenuControlObject, here I will attach Script called MainMenuControl so our buttons will properly work.


Here I drag Level 2 and 3 buttons.

Lets get started to our Level 1 Scene, In my asset I double click Level 1 Scene. Then same procedure, I created several objects such as text for LevelNumber, GameOver and YouWin texts. After that I drag my player, meteor and start object into the scene.


                                       Text Scene
                

            In the texts, I have the same setup except to the script file in Level Number. The star and meteor has their own 2D Collider where IsTrigger is Enabled while on my player I have RigidBody 2D 2D Collider isTrigger is Disabled and gravity scale to 0. Then I created an Empty Object called LevelControl I need Script for all of this objects to work out. 

       Level Control Script

Meteor Script

Player Movement Script

Star Script

Now We are nearly done, lets create folder called prefab; from the Level01 Scene, I need to drop all the objects inside the prefab. From here I will copy the objects and drag to our proceeding scenes which 2 and 3.
     Prefab Container

                
Level 3 Scene

  Level 2 Scene


                                                    
                                                   
Now we are done, here is my final output. Thank you.

Thursday, 19 November 2020

Activity 5: Shoot and Point w/ explosion

        

       In this blog, I am going to share my ways how did I created a Shooting and Pointing Player Gameplay using Unity 2D. Among other activities, the usage of components are getting much wider from hereon. 


Now we are going to need to create objects such as a player, enemy, game map, bullet, turret, and crosshair. We can produce these objects using Adobe AI. Let's drag and drop our object in project>Assets.




Then let's drop these Objects into our Scene, First, the Crosshair and Turret along I created Script called pointandshoot, and then I applied it to the Main Camera. 


PointandShoot Script



Here we apply Crosshair Object as my mouse cursor


After that, I need to create Gameobject so that our turret will move as intended, set its position to "0" put inside the turret as a child, then the same applies to our turret base. Then we drag bullet prefab into our Screen and apply component "RigidBody2D" then set Drag & Gravity to "0" and "BoxCollider2D" set trigger, and drag back again it into our Project Asset Tab. Then we delete it in the Scene. 

Next, in my Turret Parent, we created another empty object called "BulletStart" so the bullet will come out and not disperse around the turret. Position it within the tip of the turret



Then put it set the player to Turretholder and bullet Prefab in our MainCamera Script



I also created a Script for bullet optional if you want to have a scoring you can refer to my previous blog(act 4).

Bullet Script Content


                      
              Bullet Components


Now I applied Turret Station where I will add another script called playermovement (previous code)that will allow us to move using the "WASD" key. And then make it as the parent of our turretHolder. 


                                         Station Properties


Then I add the battlefield map and  3 plane targets. Let's make sure that they will appear on the scene by adjust their Z position in Inspector.

Airplane Targets Components

                                  Hierarchy of the objects

Lastly, I created Script for targets so whenever we shoot them down they will explode for a certain amount of bullet hit them. We apply the script to the airplanes as they are our targets.

                                             Enemy Script

                                           Actual Scene


                                            Gameplay

For Clearer Explanation you can watch this tutorial

Point and Shoot: https://youtu.be/7-8nE9_FwWs

Explosion : https://youtu.be/WgLd6EahyVU


Tuesday, 6 October 2020

Activity 4: Simple Score Counter


                Creating this Simple Score Counter is a bit complicated for beginners like me because it tackles new components in Unity, specifically, the UI Component where I can use different features like canvas, positioning, and animating, defining user interaction, and sizing layouts automatically. 

Components are functionality we can provide to our game objects, Specifically, a Camera Component, a GUILayer, a Flare Layer, and an Audio Listener.

 I also used Scripts in order to read input from our game objects it interacts. It also provides the physical behavior of objects like moving an object using a keyboard or mouse.

    First, We need to import our game objects to our assets which I created using Adobe Illustrator. Here I have the red ball, coins, bombs, and frame. 



        
        Then I created a Text component from UI where I clicked it on the hierarchy Tab. It will create a canvas with a child called Text.



     It is relatively large over the Main Camera but we will not move it together to the size of the main camera. Let's move the text box in the middle and change the text to "Score" from the inspector tab. Then I created a script for Score Text, this will now display our scores from the game.

            

Score Script

Next, I drag down all game objects from assets into the Scene. Just like the previous activity, the ball movement, coin, and moving bomb have the same behavior. But the difference is whenever we collide the red ball to the coin it will record a score, while when we hit the moving bomb it will decrease the score.  


                                                         Game Scene


    


Additionally, I made another script for the ball so that it will sense the coins and bomb whenever they touch. The name of the game objects must be the same inside our switch cases so they will recognize each case. Now the Destroy() method hides the object when it triggers a collision.

    
    Here are the characteristics of my coins and bomb.                        
                
                                                                       Coin Characteristic


Bomb Characteristic



                                                                Now my final output



Saturday, 3 October 2020

Activity 3: Object Movement and Rotation

    

                     

               In this blog I will create a moving and rotating object. Just like on my recent blog, first  we must create project and select 2D Template for our Object Movement and Rotation Activity.


     
    
    After Creating the template you will proceed to our application workspace where we can create our game. Then, we must import our objects like Red ball, Brick, platform, and frame which I created using Adobe Illustrator. 

   



Now that we have all we need. On my red ball and Frame, the settings were the same last time. While in my bricks and platform we only use box collider components. I need to make the bricks move on its own and the platform to rotate 360. We use scripting to create their movements.

This is our code for the bricks. The properties we set in order to make it move up-down on the first brick and from upper left to downright.

  


                                                   up down

                        


                                upper left to downright

                        



For our platform rotation movement, I used degreespersec and Time.deltaTime, this procedure will calculate how fast our rotation will be then the transform.localRotation.eulerAngles.Z holds the Z position while the Quaternion.Euler is the method that returns the rotation.
                
       

                                   Platform Object Properties
                     


This is the final result of the Object Movement and Rotation I created.

       




Tuesday, 8 September 2020

Activity 2 : Game Development


          How to add an object or obstacle to make it move, create a simple game in unity

 In this blog, I will share with you step by step how I develop a unity basic game as part of our activity in CS Elective 2 Class which is a Game Development subject.


First of all, we must first create a new project, select 2d then you can name it whatever you want and we can continue.



After that select your newly created project, Unity game development interface will pop up. In this interface, this is our working area where lots of buttons and terminologies of components are not familiar to me.




Next, Here I created our necessary object for our game like the ball, platform, and the brick using Adobe Illustrator. You can see in the picture that it is already there, simply we can just drag and drop our PNG Pictures inside the Asset tab. 


 Now we can start, Put the ball inside our scene, at the right of the asset tab we can see the Game tab which is the actual output of our design. Going back to the ball, click it, at the far right we can see the properties and its characteristics, and down below there is the add component button.



Select the Add Component button, search for Rigidbody 2d & Circle collider 2D and add them, which will enable the physics of the ball having a movement and collision sensor. Change the gravity scale to 0 in Rigidbody 2d so it will not move on its own. 

The RigidBody 2D

The Circle Collider 2D


Next is we create a box frame using our plank from the asset, just copy-paste the single plank to recreate and position them each side of the frame. Meanwhile, let's add Rigidbody 2d and Box Collider 2d to each of them. 




We change nothing in our box collider but we will the Rigidbody 2d so the object frame remains from its position. For that, we need to check all of the boxes inside of constraints (X, Y, Z).


Then let us add another plank where our brick will stand. Apply the same method the way we did to the box frame, get the Rigidbody 2d, then check all boxes in constraints and Box Collider 2d from the components.



After that place the brick on the platform in the middle. We can duplicate the single box to form a pyramid (5 bricks). After that, each of them must have Rigidbody 2d and Box Collider 2d. We will just need to change the gravity scale to 2  and Collision Detection from discrete to continue. 



And for the last part of our development, we need to create a scripting file that will allow us to control the ball using WASD keys. Just select the ball on our scene, proceed to add components, Select new script then type the name of the script lastly, click select and add. After doing that you will see the script file in the assets together with our png pictures. 


Open that scripting file and we type this code using visual studio code.




Go back to your unity and change ball speed to 10 from your script component. And now we can run the game






Viola, this is our finished product.




PS. In case encountering that some variables in unity are not recognized by the suggestion library. I'd like to give you this fix if you encounter it. Go to Unity, Edit > Preferences, Select External Script Editor: Visual Studio Community. This will fix your problem.


 




Activity 8: Game Level Feature

              This blog contains information about next level features using Unity 2D.  First, We need Following Image Objects : Player, Met...