Advertisement
Guest User

Color Collider source

a guest
Dec 7th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerColor : MonoBehaviour {
  5.     public int CurColor;
  6.     public Color C1;
  7.     public Color C2;
  8.     public Color C3;
  9.     public Color C4;
  10.  
  11.     public float Vspeed;
  12.     public float Hspeed;
  13.     public float Score;
  14.     public float HighScore;
  15.  
  16.     public bool MoveRight;
  17.  
  18.     public bool dead = false;
  19.  
  20.     public GUIStyle main;
  21.     // Use this for initialization
  22.     void Start () {
  23.         Time.timeScale = 1;
  24.         CurColor = Random.Range(1,4);
  25.         InvokeRepeating("ChangeCurColor",0.8f,0.8f);
  26.        
  27.         }
  28.    
  29.     // Update is called once per frame
  30.     void Update () {
  31.  
  32.  
  33.         if(MoveRight){
  34.             transform.Translate(Hspeed * Time.deltaTime, 0,0);
  35.         } else if(!MoveRight){
  36.             transform.Translate(-Hspeed * Time.deltaTime, 0,0);
  37.  
  38.         }
  39.  
  40.         ChangeColor();
  41.  
  42.         float input = Input.GetAxis("Vertical");
  43.         transform.Translate(0, input * Vspeed * Time.deltaTime,0);
  44.     }
  45.     void ChangeCurColor () {
  46.         CurColor++;
  47.         if(CurColor > 4) {
  48.             CurColor = 1;
  49.         }
  50.     }
  51.     void ChangeColor () {
  52.         if(CurColor == 1) {
  53.             renderer.material.color = C1;
  54.         //  main.normal.textColor = C1;
  55.  
  56.         }
  57.         if(CurColor == 2) {
  58.             renderer.material.color = C2;
  59.         //  main.normal.textColor = C2;
  60.  
  61.         }
  62.         if(CurColor == 3) {
  63.             renderer.material.color = C3;
  64.             //main.normal.textColor = C3;
  65.  
  66.         }
  67.         if(CurColor == 4) {
  68.             renderer.material.color = C4;
  69.             //main.normal.textColor = C4;
  70.            
  71.         }
  72.     }
  73.     void OnTriggerEnter (Collider trigger) {
  74.         if(trigger.transform.tag == "LeftColors") {
  75.             MoveRight = true;
  76.  
  77.             Debug.Log("Hit LeftColors");
  78.         }
  79.  
  80.      if (trigger.transform.tag == "RightColors") {
  81.             MoveRight = false;
  82.             Debug.Log("Hit RightColors");
  83.  
  84.         }
  85.  
  86.         if(trigger.name == "" + CurColor) {
  87.  
  88.             Score++;
  89.         }
  90.         else {
  91.             Die();
  92.         }
  93.     }
  94.     void Die() {
  95.         dead = true;
  96.         Time.timeScale = 0;
  97.         if(Score > PlayerPrefs.GetFloat("Highscore")) {
  98.             PlayerPrefs.SetFloat("Highscore", Score);
  99.         }
  100.         Application.LoadLevel(Application.loadedLevel);
  101.     }
  102.     void OnGUI() {
  103.         GUI.Label(new Rect(10, 10, Screen.width, Screen.height), "Score: " + Score, main);
  104.         GUI.Label(new Rect(10, 50, Screen.width, Screen.height), "Highscore: " + PlayerPrefs.GetFloat("Highscore"), main);
  105.  
  106.        
  107.        
  108.  
  109.    
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement