Unity for Windows IX–Creating a more advanced game, Part 4

image

This tutorial will continue from the previous tutorial in this series.

Today we are going to add explosions, level ups and a UI.

Download the source and assets here.

I. Creating explosions

When a player dies, we want to make it dead, and make it explode!

First of all, we will make the movement stop and play the death animation. And then after one second, we will make it explode.

To do this, we need to edit the EnemyHandler script. What we will do is to add two prefabs that represent the explosion and smoke, then a boolean that indicates of the enemy is dead or not, and then a timer that will be set and counted after it is dead – resulting in an explosion after 0.5 seconds.

To change the animation that our enemy is playing, we need a reference to the AnimationHandler component of the current player. The can be found using GetComponent – it returns a component attached to the current Game Object.

Then, when the enemy is hit, we set the animation to dead, and then set the boolean isDead to true.

When this is true, we will start spawning the smokePrefab, and start the timer.

After 0.5 seconds, the timer is over and the enemy is dead + spawning an explosion.

Also, if the enemy hits the player, it will explode instantly. We also stop the enemy movement when the dead animation is playing.

Here is the code, try to see if you can understand it – it should not be anything new (except for GetComponent), just new ways to combine our rules to make our logic the way we want Smilefjes

using UnityEngine;
using System.Collections;

public class EnemyHandler : MonoBehaviour
{
    float speed = 4.0f;
    GameObject player;

    public GameObject explodePrefab;
    public GameObject smokePrefab;
    bool isDead = false;
    float isDeadTimer = 0.5f;

    AnimationHandler animationHandler;

    void OnCollisionEnter(Collision collision)
    {
        if (collision.rigidbody != null)
        {
            if (collision.rigidbody.name == “Player”)
            {
               
Instantiate(explodePrefab, this.transform.position, Quaternion.identity);
                Instantiate(smokePrefab, this.transform.position, Quaternion.identity);

                Destroy(this.gameObject);
            }

            if (collision.rigidbody.tag == “Laser”)
            {
               
isDead = true;
                Instantiate(smokePrefab, this.transform.position, Quaternion.identity);

                Destroy(collision.gameObject);

                if (animationHandler != null)
                {
                    animationHandler.playAnimationSetNumber = 0;
                }
            }
        }
    }
    // Use this for initialization
    void Start()
    {
        GameObject _p = GameObject.Find(“Player”);
        if (_p != null)
        {
            player = _p;
        }

        animationHandler = this.GetComponent<AnimationHandler>();
       
    }

    // Update is called once per frame
    void Update()
    {
       
if (isDead)
        {
            isDeadTimer -= Time.deltaTime;
        }

       if (!isDead)
        {

            Vector3 moveVector = Vector3.left;
            transform.position += moveVector * speed * Time.deltaTime;
        }

        if (player != null)
        {
            if (this.transform.position.x <= player.transform.position.x – 10.0f)
            {
                Destroy(this.gameObject);
            }
        }

       if (isDeadTimer <= 0.0f)
        {
            Instantiate(explodePrefab, this.transform.position, Quaternion.identity);
            Destroy(this.gameObject);
           
        }

    }
}

Ok! Try to play the gama again now, and it suddenly feels much better – more action!

 

II. Adding hitpoints to the player

When we hit a player, it will explode – but we also want this to reduce the current health the player is having.

Open the PlayerHandler script and make the following modifications:

using UnityEngine;
using System.Collections;

public class PlayerHandler : MonoBehaviour {
    float speed = 4.0f;
    public GameObject laserPrefab;

    float shootTimer = 0.0f;
    float setShootTimerTo = 0.5f;

    public int HP;

    void OnCollisionEnter(Collision collision)
    {
        if (collision.rigidbody != null)
        {
            if (collision.rigidbody.tag == “Enemy”)
            {
                HP -= 1;
            }
        }
    }

    // Use this for initialization
    void Start () {
   
    }
   
    // Update is called once per frame
    void Update () {
        Vector3 movePlayerVector = Vector3.right;
        shootTimer -= Time.deltaTime;

        if (Input.GetMouseButton(0))
        {
            Vector3 touchWorldPoint = Camera.main.ScreenToWorldPoint(
                new Vector3(Input.mousePosition.x,
                            Input.mousePosition.y,
                            10.0f));

            if (touchWorldPoint.x < this.transform.position.x + 5.0f)
            {
                if (touchWorldPoint.y > this.transform.position.y)
                {
                    movePlayerVector.y = 1.0f;
                }
                else movePlayerVector.y = -1.0f;
            }
            else
            {
                if (shootTimer <= 0)
                {
                    Vector3 shootPos = this.transform.position;
                    shootPos.x += 2;
                    Instantiate(laserPrefab, shootPos, Quaternion.identity);
                    shootTimer = setShootTimerTo;
                }
            }
        }

        this.transform.position += movePlayerVector * Time.deltaTime * speed;

        if (transform.position.y > -2.0)
        {
            transform.position = new Vector3(transform.position.x,
                                            -2.0f,
                                            transform.position.z);
        }

        if (transform.position.y < -5.5)
        {
            transform.position = new Vector3(transform.position.x,
                                            -5.5f,
                                            transform.position.z);
        }
    }
}

Now, click the Player game object in the scene hierarchy and set the HP property to 10.

image

Press play and click the Player Game Object in the scene hierarchy. Take a look at the HP property and see that it will be reduced when we hit an enemy.

image

 

The last thing (for now) that we will do on the player is to show that we took damage when an enemy hits us. Then the enemy hits us, we set the color of our material to red, and then slowly fade back to white (white = original colors in the texture).

Modify the PlayerHandler script with the following changes:

using UnityEngine;
using System.Collections;

public class PlayerHandler : MonoBehaviour {
    float speed = 4.0f;
    public GameObject laserPrefab;
    public GameObject textureObject;

    float shootTimer = 0.0f;
    float setShootTimerTo = 0.5f;

    public int HP;
    float colorModifier = 1.0f;

    void OnCollisionEnter(Collision collision)
    {
        if (collision.rigidbody != null)
        {
            if (collision.rigidbody.tag == “Enemy”)
            {
                HP -= 1;
                colorModifier = 0.0f;
            }
        }
    }

    // Use this for initialization
    void Start () {
    }
   
    // Update is called once per frame
    void Update () {
        Vector3 movePlayerVector = Vector3.right;
        shootTimer -= Time.deltaTime;

        textureObject.gameObject.renderer.material.color = new Color(1.0f, colorModifier, colorModifier);

        if(colorModifier < 1.0f)
            colorModifier += Time.deltaTime;

        if (Input.GetMouseButton(0))
        {
            Vector3 touchWorldPoint = Camera.main.ScreenToWorldPoint(
                new Vector3(Input.mousePosition.x,
                            Input.mousePosition.y,
                            10.0f));

            if (touchWorldPoint.x < this.transform.position.x + 5.0f)
            {
                if (touchWorldPoint.y > this.transform.position.y)
                {
                    movePlayerVector.y = 1.0f;
                }
                else movePlayerVector.y = -1.0f;
            }
            else
            {
                if (shootTimer <= 0)
                {
                    Vector3 shootPos = this.transform.position;
                    shootPos.x += 2;
                    Instantiate(laserPrefab, shootPos, Quaternion.identity);
                    shootTimer = setShootTimerTo;
                }
            }
        }

        this.transform.position += movePlayerVector * Time.deltaTime * speed;

        if (transform.position.y > -2.0)
        {
            transform.position = new Vector3(transform.position.x,
                                            -2.0f,
                                            transform.position.z);
        }

        if (transform.position.y < -5.5)
        {
            transform.position = new Vector3(transform.position.x,
                                            -5.5f,
                                            transform.position.z);
        }
    }
}

As you can see, we also grabed the Texture component in a public variable, so this needs to be set.

Set the Texture Object of the Player to the Texture Game Object inside the player:

image

image

Also, click on the Texture of the Player game object and change the shader to:
image

This is because we want to be able to change the color of the material and see it in the texture in-game.

Now, the code works like this. We set the modifier to 0.0f, and whenever this is not 1.0f, we increase it so it becomes 1.0f (white). Then we set the color using this. When hit, the value of the modifier is 0.0f, thus the color of the material is 1,0,0 (red). Then we slowly increase the zeroes untill its 1,1,1 (white) again.

Press play now and let an enemy hit you. You can see that you also turn red and fade back to the normal color.
image

 

III. Giving the player Xp

When we kill an enemy, we want to reward the player with experience points, that will be used to level up (and increase how hard the game is).

Still in the PlayerHandler script, we create a new integer that is our current xp and another one that keeps track of the players level (the other level that is in the game handler is the current game level we are playing (how frequent and how enemies should spawn):

using UnityEngine;
using System.Collections;

public class PlayerHandler : MonoBehaviour {
    float speed = 4.0f;
    public GameObject laserPrefab;
    public GameObject textureObject;

    float shootTimer = 0.0f;
    float setShootTimerTo = 0.5f;

    public int Xp = 0;
    public int Level = 0;

    public int HP;
    float colorModifier = 1.0f;

    void OnCollisionEnter(Collision collision)
    {
        if (collision.rigidbody != null)
        {
            if (collision.rigidbody.tag == “Enemy”)
            {
                HP -= 1;
                colorModifier = 0.0f;
            }
        }
    }

    // Use this for initialization
    void Start () {
    }
   
    // Update is called once per frame
    void Update () {
        Vector3 movePlayerVector = Vector3.right;
        shootTimer -= Time.deltaTime;

        textureObject.gameObject.renderer.material.color = new Color(1.0f, colorModifier, colorModifier);

        if(colorModifier < 1.0f)
            colorModifier += Time.deltaTime;

        if (Input.GetMouseButton(0))
        {
            Vector3 touchWorldPoint = Camera.main.ScreenToWorldPoint(
                new Vector3(Input.mousePosition.x,
                            Input.mousePosition.y,
                            10.0f));

            if (touchWorldPoint.x < this.transform.position.x + 5.0f)
            {
                if (touchWorldPoint.y > this.transform.position.y)
                {
                    movePlayerVector.y = 1.0f;
                }
                else movePlayerVector.y = -1.0f;
            }
            else
            {
                if (shootTimer <= 0)
                {
                    Vector3 shootPos = this.transform.position;
                    shootPos.x += 2;
                    Instantiate(laserPrefab, shootPos, Quaternion.identity);
                    shootTimer = setShootTimerTo;
                }
            }
        }

        this.transform.position += movePlayerVector * Time.deltaTime * speed;

        if (transform.position.y > -2.0)
        {
            transform.position = new Vector3(transform.position.x,
                                            -2.0f,
                                            transform.position.z);
        }

        if (transform.position.y < -5.5)
        {
            transform.position = new Vector3(transform.position.x,
                                            -5.5f,
                                            transform.position.z);
        }
    }
}

Then in the Enemy script, if we kill the enemy, we add Xp to the player based on how difficlt the enemy is. Open the EnemyHandler script and do the following changes:

using UnityEngine;
using System.Collections;

public class EnemyHandler : MonoBehaviour
{
    float speed = 4.0f;
    GameObject player;

    public GameObject explodePrefab;
    public GameObject smokePrefab;
    bool isDead = false;
    float isDeadTimer = 0.5f;
    public int enemyDifficulty;

    AnimationHandler animationHandler;
    PlayerHandler playerHandler;

    void OnCollisionEnter(Collision collision)
    {
        if (collision.rigidbody != null)
        {
            if (collision.rigidbody.name == “Player”)
            {
                Instantiate(explodePrefab, this.transform.position, Quaternion.identity);
                Instantiate(smokePrefab, this.transform.position, Quaternion.identity);
                Destroy(this.gameObject);
            }

            if (collision.rigidbody.tag == “Laser”)
            {
                isDead = true;
                Instantiate(smokePrefab, this.transform.position, Quaternion.identity);

                Destroy(collision.gameObject);

                if (animationHandler != null)
                {
                    animationHandler.playAnimationSetNumber = 0;
                }
            }
        }
    }
    // Use this for initialization
    void Start()
    {
        GameObject _p = GameObject.Find(“Player”);
        if (_p != null)
        {
            player = _p;

            playerHandler = player.GetComponent<PlayerHandler>();
        }

        animationHandler = this.GetComponent<AnimationHandler>();
       
    }

    // Update is called once per frame
    void Update()
    {
        if (isDead)
        {
            isDeadTimer -= Time.deltaTime;
        }

        if (!isDead)
        {
            Vector3 moveVector = Vector3.left;
            transform.position += moveVector * speed * Time.deltaTime;
        }

        if (player != null)
        {
            if (this.transform.position.x <= player.transform.position.x – 10.0f)
            {
                Destroy(this.gameObject);
            }
        }

        if (isDeadTimer <= 0.0f)
        {
            Instantiate(explodePrefab, this.transform.position, Quaternion.identity);
            Destroy(this.gameObject);
            playerHandler.Xp += enemyDifficulty * 10;
        }
    }
}

What we are doing here is to create a new public variable for the enemy, the difficulty in Level. Then in the Start() function, we find the PlayerHandler component of the player object and if the enemy is dead, we add 10 x the level of our enemy (difficulty) to the players Xp.

Go to the enemy prefab and set the difficulty to 1:
image

image

Play the game and make sure you are getting Xp! Smilefjes

 

IV. Increasing the players level

The next thing we want to do is to increase the players level based on the Xp he gets.

We do this in the PlayerHandler script. What we will do is to create a lookup list that contains what XP is needed to become a given level.

Then, we set the players level to this level based on the Xp.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class PlayerHandler : MonoBehaviour {
    float speed = 4.0f;
    public GameObject laserPrefab;
    public GameObject textureObject;

    float shootTimer = 0.0f;
    float setShootTimerTo = 0.5f;

    public int Xp = 0;
    public int Level = 0;

    List<int> levelList = new List<int>();

    public int HP;
    float colorModifier = 1.0f;

    void OnCollisionEnter(Collision collision)
    {
        if (collision.rigidbody != null)
        {
            if (collision.rigidbody.tag == “Enemy”)
            {
                HP -= 1;
                colorModifier = 0.0f;
            }
        }
    }

    // Use this for initialization
    void Start () {
       
for (int i = 0; i < 20; i++)
        {
            levelList.Add((int)(50 + (i * 50) + (i * 50 * 0.25)));
        }

    }
   
    // Update is called once per frame
    void Update () {
        Vector3 movePlayerVector = Vector3.right;
        shootTimer -= Time.deltaTime;

        textureObject.gameObject.renderer.material.color = new Color(1.0f, colorModifier, colorModifier);

        if(colorModifier < 1.0f)
            colorModifier += Time.deltaTime;

        if (Input.GetMouseButton(0))
        {
            Vector3 touchWorldPoint = Camera.main.ScreenToWorldPoint(
                new Vector3(Input.mousePosition.x,
                            Input.mousePosition.y,
                            10.0f));

            if (touchWorldPoint.x < this.transform.position.x + 5.0f)
            {
                if (touchWorldPoint.y > this.transform.position.y)
                {
                    movePlayerVector.y = 1.0f;
                }
                else movePlayerVector.y = -1.0f;
            }
            else
            {
                if (shootTimer <= 0)
                {
                    Vector3 shootPos = this.transform.position;
                    shootPos.x += 2;
                    Instantiate(laserPrefab, shootPos, Quaternion.identity);
                    shootTimer = setShootTimerTo;
                }
            }
        }

        this.transform.position += movePlayerVector * Time.deltaTime * speed;

        if (transform.position.y > -2.0)
        {
            transform.position = new Vector3(transform.position.x,
                                            -2.0f,
                                            transform.position.z);
        }

        if (transform.position.y < -5.5)
        {
            transform.position = new Vector3(transform.position.x,
                                            -5.5f,
                                            transform.position.z);
        }


        if (Xp >= levelList[Level])
        {
             Level++;
        }
    }
}

In the GameHandler script, we want to make the game harder and harder over time. There are multiple design choises on how this can be done. You can make the level of the game just as hard as the level you are at, or you can make the game harder and harder over time and then it’s up to who you take out and what you do that you can keep up with how hard the game is.

We are going for the first, we are making the game harder and harder based on what level the player currently is.

In the GameHandler, we create a reference to the PlayerHandler, and then set the level integer of the game to equal the level of the player:

using UnityEngine;
using System.Collections;
public class GameHandler : MonoBehaviour
{
    public int level;

    public GameObject enemy;
    public GameObject player;

    public PlayerHandler playerHandler;

    float spawnNewEnemyTimer = 10;

    // Use this for initialization
    void Start()
    {
        playerHandler = player.GetComponent<PlayerHandler>();
    }

    // Update is called once per frame
    void Update()
    {
        spawnNewEnemyTimer -= Time.deltaTime;
        if (spawnNewEnemyTimer <= 0)
        {
            spawnNewEnemyTimer = 5 – (level * 0.25f);
            if (spawnNewEnemyTimer < 0.5f)
                spawnNewEnemyTimer = 0.5f;

            Instantiate(enemy, new Vector3(player.transform.position.x + 100.0f,
                    player.transform.position.y, 0.0f), Quaternion.identity);
        }

        if (playerHandler != null)
        {
            level = playerHandler.Level;
        }

    }
}

Cool! We now set the game level to reflect the players level.

Now, let’s make the game a bit harder as well (and not just increaseing the frequence of how often the player is spawned).

If you are Level 2 and above, we want to spawn 2 enemies instead of just one.

Modify the GameHandler additionally:

using UnityEngine;
using System.Collections;
public class GameHandler : MonoBehaviour
{
    public int level;

    public GameObject enemy;
    public GameObject player;

    public PlayerHandler playerHandler;

    float spawnNewEnemyTimer = 10;

    // Use this for initialization
    void Start()
    {
        playerHandler = player.GetComponent<PlayerHandler>();
    }

    // Update is called once per frame
    void Update()
    {
        spawnNewEnemyTimer -= Time.deltaTime;
    
   if (spawnNewEnemyTimer <= 0)
        {
            spawnNewEnemyTimer = 5 – (level * 0.25f);
            if (spawnNewEnemyTimer < 0.5f)
                spawnNewEnemyTimer = 0.5f;

            int spawnNumberOfEnemies = 1 + (level/3);
            for (int i = 0; i < spawnNumberOfEnemies; i++)
            {
                float modifier = Random.Range(0.0f, 1.0f);
                Instantiate(enemy, new Vector3(player.transform.position.x + 100.0f + i*10,
                       player.transform.position.y + modifier, 0.0f), Quaternion.identity);
            }

        }

        if (playerHandler != null)
        {
            level = playerHandler.Level;
        }
    }
}

The logic here is that we are spawning a given number of enemies based on what level we are. If we are level 1 and 2, we spawn 1 enemy. And then every thirst level from there spawns an additional enemy.

If you play the game for a while now, you can see this change in the game.

V. Adding the User Interface

We do the same as in tutorial 4. Add a new and empty game object to the scene and name it GUI:

image

Then add a GUITexture Game Object to it, and name it PlayerInfoTexture:
image

Then, click the UI Texture in the Textures folder (can be found in this projects assets folder) and change it to GUI:

image

Click Apply to save the changes. Then drag this texture on the GUI Texture we just added to the GUI Game Object and set the properties to the following:
image

Next, we want to add a text that shows our level and the Xp that we got left untill we get to a new level.

Add a new GUI Text game object to the scene and name it “LevelLabel”:
image

Set the properties to the following:
image

 

Duplicate the LevelLabel and rename it to XpLabel:
image

 

And modify the properties to the following:
image

Cool! We got our simple UI working! The last thing we need to do is to set the labels from our GameHandler script.

First, we need to make the levelList in the PlayerHandler public. Modify the script so it looks like this (one line):

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class PlayerHandler : MonoBehaviour {
    float speed = 4.0f;
    public GameObject laserPrefab;
    public GameObject textureObject;

    float shootTimer = 0.0f;
    float setShootTimerTo = 0.5f;

    public int Xp = 0;
    public int Level = 0;

    public List<int> levelList = new List<int>();
    PlayerHandler playerHandler;

    public int HP;
    float colorModifier = 1.0f;

    void OnCollisionEnter(Collision collision)
    {
        if (collision.rigidbody != null)
        {
            if (collision.rigidbody.tag == “Enemy”)
            {
                HP -= 1;
                colorModifier = 0.0f;
            }
        }
    }

    // Use this for initialization
    void Start () {
        for (int i = 0; i < 20; i++)
        {
            levelList.Add((int)(50 + (i * 50) + (i * 50 * 0.25)));
        }
        playerHandler = this.GetComponent<PlayerHandler>();

    }
   
    // Update is called once per frame
    void Update () {
        Vector3 movePlayerVector = Vector3.right;
        shootTimer -= Time.deltaTime;

        textureObject.gameObject.renderer.material.color = new Color(1.0f, colorModifier, colorModifier);

        if(colorModifier < 1.0f)
            colorModifier += Time.deltaTime;

        if (Input.GetMouseButton(0))
        {
            Vector3 touchWorldPoint = Camera.main.ScreenToWorldPoint(
                new Vector3(Input.mousePosition.x,
                            Input.mousePosition.y,
                            10.0f));

            if (touchWorldPoint.x < this.transform.position.x + 5.0f)
            {
                if (touchWorldPoint.y > this.transform.position.y)
                {
                    movePlayerVector.y = 1.0f;
                }
                else movePlayerVector.y = -1.0f;
            }
            else
            {
                if (shootTimer <= 0)
                {
                    Vector3 shootPos = this.transform.position;
                    shootPos.x += 2;
                    Instantiate(laserPrefab, shootPos, Quaternion.identity);
                    shootTimer = setShootTimerTo;
                }
            }
        }

        this.transform.position += movePlayerVector * Time.deltaTime * speed;

        if (transform.position.y > -2.0)
        {
            transform.position = new Vector3(transform.position.x,
                                            -2.0f,
                                            transform.position.z);
        }

        if (transform.position.y < -5.5)
        {
            transform.position = new Vector3(transform.position.x,
                                            -5.5f,
                                            transform.position.z);
        }

        if (playerHandler.Xp >= levelList[Level])
        {
            Level++;
        }
    }
}

Then save and open the GameHandler script. Edit the script and make the following modifications:

using UnityEngine;
using System.Collections;
public class GameHandler : MonoBehaviour
{
    public int level;

    public GameObject enemy;
    public GameObject player;

    public PlayerHandler playerHandler;

    public GUIText levelLabel;
    public GUIText xpLabel;

    float spawnNewEnemyTimer = 10;

    // Use this for initialization
    void Start()
    {
        playerHandler = player.GetComponent<PlayerHandler>();
    }

    // Update is called once per frame
    void Update()
    {
        spawnNewEnemyTimer -= Time.deltaTime;
        if (spawnNewEnemyTimer <= 0)
        {
            spawnNewEnemyTimer = 5 – (level * 0.25f);
            if (spawnNewEnemyTimer < 0.5f)
                spawnNewEnemyTimer = 0.5f;

            int spawnNumberOfEnemies = 1 + (level/3);
            for (int i = 0; i < spawnNumberOfEnemies; i++)
            {
                float modifier = Random.Range(0.0f, 1.0f);
                Instantiate(enemy, new Vector3(player.transform.position.x + 100.0f + i*10,
                       player.transform.position.y + modifier, 0.0f), Quaternion.identity);
            }

        }

        if (playerHandler != null)
        {
            level = playerHandler.Level;

            levelLabel.text = “Level ” + (level+1);

            int xpInLevel = playerHandler.Xp;
            if (level > 0)
            {
                xpInLevel = playerHandler.Xp – playerHandler.levelList[level – 1];
            }

            int xpForNextLevel = (playerHandler.levelList[level]);
            if(level > 0)
                xpForNextLevel = playerHandler.levelList[level] – playerHandler.levelList[level – 1];

            xpLabel.text = xpInLevel + “/” + xpForNextLevel;
        }
    }
}

This script simply calculates how much Xp is needed for the current level, how much the player got and then renders it in the xp label. The level label is also updated with the current level.

Set the referneces to the labels on the Main Camera like this:
image

Press play to see our game in action! Smilefjes

image

The game is now playable and pretty much awesome! You can play, kill stuff, see the explosions and the levels going up!

 

VI. Fixing the bad performance

There is ONE last thing we need to do in this tutorial.. as you keep playing, you can feel that the game starts lagging after a while. This is because the particles that renders our smoke keeps staying alive forever, resulting in thousands of particles being rendered in the scene.

We do this by adding a cutof script that comes with the standard assets folder.

First, find the Fluffy Smoke particle engine and click it to view the properties:

image

 

Find the TimedObjectDestructor script in the Legacy Particles script folder:

image

And drag it on the to the components area of the properties (its not very big):

image

(You release it when you see the mouse pointer turn in to something that looks like you can add stuff there)

Set the properties of the component to the following:
image

This means that the smoke system will automatically be destroyed after 5.0 seconds.

Give it a try, the performance of the game is much better! Smilefjes med åpen munn

Now – the game is getting impossible and even more laggy after a while so the next tutorial is all about finetuning, doing some balancing, spawning another type of enemy and picking up power ups and adding the UI for player health. We will also create the main menu, game over scene and publish it to the store.

Download the source and assets here.

This entry was posted in Tutorial, Unity. Bookmark the permalink.

2 Responses to Unity for Windows IX–Creating a more advanced game, Part 4

  1. Andreas says:

    The enemy will not change to the dead-animation if I hit him with the laser. Strangely is, that the animation works perfectly fine, if I just change the number in Unity.

    I copied your code, but it still won`t work. What do I do wrong?

  2. Josh says:

    This is a few months after you asked the question, but for anyone else that stumbles on this, you want to play animation 2, not animation 0. Animation 2 is the death animation (at least in how the array is setup in this tutorial…which is awesome!)

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.