Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlayerColor : MonoBehaviour {
- public int CurColor;
- public Color C1;
- public Color C2;
- public Color C3;
- public Color C4;
- public float Vspeed;
- public float Hspeed;
- public float Score;
- public float HighScore;
- public bool MoveRight;
- public bool dead = false;
- public GUIStyle main;
- // Use this for initialization
- void Start () {
- Time.timeScale = 1;
- CurColor = Random.Range(1,4);
- InvokeRepeating("ChangeCurColor",0.8f,0.8f);
- }
- // Update is called once per frame
- void Update () {
- if(MoveRight){
- transform.Translate(Hspeed * Time.deltaTime, 0,0);
- } else if(!MoveRight){
- transform.Translate(-Hspeed * Time.deltaTime, 0,0);
- }
- ChangeColor();
- float input = Input.GetAxis("Vertical");
- transform.Translate(0, input * Vspeed * Time.deltaTime,0);
- }
- void ChangeCurColor () {
- CurColor++;
- if(CurColor > 4) {
- CurColor = 1;
- }
- }
- void ChangeColor () {
- if(CurColor == 1) {
- renderer.material.color = C1;
- // main.normal.textColor = C1;
- }
- if(CurColor == 2) {
- renderer.material.color = C2;
- // main.normal.textColor = C2;
- }
- if(CurColor == 3) {
- renderer.material.color = C3;
- //main.normal.textColor = C3;
- }
- if(CurColor == 4) {
- renderer.material.color = C4;
- //main.normal.textColor = C4;
- }
- }
- void OnTriggerEnter (Collider trigger) {
- if(trigger.transform.tag == "LeftColors") {
- MoveRight = true;
- Debug.Log("Hit LeftColors");
- }
- if (trigger.transform.tag == "RightColors") {
- MoveRight = false;
- Debug.Log("Hit RightColors");
- }
- if(trigger.name == "" + CurColor) {
- Score++;
- }
- else {
- Die();
- }
- }
- void Die() {
- dead = true;
- Time.timeScale = 0;
- if(Score > PlayerPrefs.GetFloat("Highscore")) {
- PlayerPrefs.SetFloat("Highscore", Score);
- }
- Application.LoadLevel(Application.loadedLevel);
- }
- void OnGUI() {
- GUI.Label(new Rect(10, 10, Screen.width, Screen.height), "Score: " + Score, main);
- GUI.Label(new Rect(10, 50, Screen.width, Screen.height), "Highscore: " + PlayerPrefs.GetFloat("Highscore"), main);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement