CubeBehaviour.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. 
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class CubeBehaviour : MonoBehaviour {
  6. public int framesPerRotation = 20;
  7. public int waitingFrames = 30;
  8. public string currentSymbol = "black";
  9. static bool currentlyMooving = false;
  10. public bool uncovered = false;
  11. // Use this for initialization
  12. void Start () {
  13. }
  14. // Update is called once per frame
  15. void Update () {
  16. }
  17. void OnMouseDown(){
  18. StartRotation();
  19. }
  20. public void StartRotation(){
  21. if (!(currentlyMooving || uncovered)) {
  22. StartCoroutine (RotateOnClick ());
  23. }
  24. }
  25. IEnumerator RotateOnClick(){
  26. currentlyMooving = true;
  27. for(int i = 0; i < framesPerRotation; i++){
  28. transform.RotateAround (transform.position, Vector3.down, (float)180 / framesPerRotation);
  29. yield return null;
  30. }
  31. if (currentSymbol != "black") {
  32. uncovered = true;
  33. } else {
  34. for(int i = 0; i < waitingFrames; i++){
  35. yield return null;
  36. }
  37. for(int i = 0; i < framesPerRotation; i++){
  38. transform.RotateAround (transform.position, Vector3.down, (float)180 / framesPerRotation);
  39. yield return null;
  40. }
  41. }
  42. currentlyMooving = false;
  43. }
  44. public void ToggleToRed(){
  45. currentSymbol = "red";
  46. GetComponentsInChildren<MeshRenderer> () [1].enabled = true;
  47. GetComponentsInChildren<MeshRenderer> () [2].enabled = false;
  48. GetComponentsInChildren<MeshRenderer> () [3].enabled = false;
  49. GetComponentsInChildren<MeshRenderer> () [4].enabled = false;
  50. }
  51. public void ToggleToBlue(){
  52. currentSymbol = "blue";
  53. GetComponentsInChildren<MeshRenderer> () [2].enabled = true;
  54. GetComponentsInChildren<MeshRenderer> () [1].enabled = false;
  55. GetComponentsInChildren<MeshRenderer> () [3].enabled = false;
  56. GetComponentsInChildren<MeshRenderer> () [4].enabled = false;
  57. }
  58. }