Last active
December 14, 2015 21:19
-
-
Save N-Carter/5150488 to your computer and use it in GitHub Desktop.
Tile class to go with EndlessTiles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| public class Tile : MonoBehaviour | |
| { | |
| [SerializeField] TextMesh m_TextMesh; | |
| protected EndlessTiles m_EndlessTiles; | |
| protected bool m_Touched; | |
| protected int m_TileIndex; | |
| protected int m_Colour; | |
| public void Reset() | |
| { | |
| m_Touched = false; | |
| m_TileIndex = Random.Range(0, 7); | |
| var materials = m_EndlessTiles.Materials; | |
| m_Colour = Random.Range(0, materials.Length); | |
| m_TextMesh.text = ((char)('A' + m_TileIndex)).ToString(); | |
| renderer.sharedMaterial = m_EndlessTiles.Materials[m_Colour]; | |
| } | |
| public void Touch() | |
| { | |
| if(!m_Touched) | |
| { | |
| if(m_TileIndex == 6) | |
| { | |
| Player.LoseLife(); | |
| } | |
| else if(m_Colour == 0) | |
| { | |
| renderer.sharedMaterial = m_EndlessTiles.TouchedMaterial; | |
| Player.AddScore(1); | |
| Player.PlaySound(0); | |
| m_Touched = true; | |
| } | |
| else | |
| { | |
| m_TextMesh.text = "G"; | |
| m_TileIndex = 6; | |
| Player.AddScore(-1); | |
| Player.SlowDown(); | |
| Player.PlaySound(1); | |
| } | |
| } | |
| } | |
| public EndlessTiles endlessTiles {get {return m_EndlessTiles;} set {m_EndlessTiles = value;}} | |
| public TextMesh textMesh {get {return m_TextMesh;}} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment