Simple Maze
This is a small maze game, The player must reach the end of the path without hitting the walls.
In this video is some information about the player’s movement and the use of some simple materials, audio and the use of post processing.
Sample pictures
C# code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | using UnityEngine; using System.Collections; public class PlayerMovement : MonoBehaviour { public float speed; float x,y; // Update is called once per frame void Update () { if (Accident.health > 0 && !End.endState) { x = Input.GetAxis("Horizontal") * speed * Time.deltaTime; y = Input.GetAxis("Vertical") * speed * Time.deltaTime; transform.Translate(x, y, 0); } else if (Accident.health > 0) { transform.Translate(-0.5f * Time.deltaTime, 0, 0); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | using UnityEngine; using System.Collections; public class Accident : MonoBehaviour { public GameObject redPanel; public GameObject losePanel; public float redTime = .3f; public AudioSource audioSource; public AudioClip loseClip; public static int health = 3; void OnCollisionEnter2D (Collision2D col){ if (col.gameObject.tag == "Wall") { StartCoroutine(Red()); GetComponent<AudioSource>().Play(); health--; if (health <= 0) { Lose(); } } } IEnumerator Red() { redPanel.SetActive(true); yield return new WaitForSeconds(redTime); redPanel.SetActive(false); } void Lose() { losePanel.SetActive(true); audioSource.clip = loseClip; audioSource.Play(); Destroy(gameObject, 5); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | using System.Collections; using System.Collections.Generic; using UnityEngine; public class Health : MonoBehaviour { public GameObject[] healthUI = new GameObject[3]; // Update is called once per frame void Update() { switch (Accident.health) { case 2: healthUI[2].SetActive(false); break; case 1: healthUI[1].SetActive(false); break; case 0: healthUI[0].SetActive(false); break; } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | using UnityEngine; using System.Collections; public class End : MonoBehaviour { public GameObject winPanel; public AudioSource audioSource; public AudioClip winClip; public static bool endState; void OnTriggerEnter2D (Collider2D col){ if (col.gameObject.tag == "Player") { winPanel.SetActive(true); audioSource.clip = winClip; audioSource.Play(); endState = true; Destroy(col.gameObject, 5); } } } |