void Update() { if (globalVariable.teleporting) { cubeFace.renderer.enabled = false; } else if (!globalVariable.teleporting && !globalVariable.endLevel) { cubeFace.renderer.enabled = true; } oldState = currentState; if (Application.loadedLevelName == "7-1" && blinkingPlayed) { setCurrentFace(determinedFace); } // Check if Moving if (globalVariable.isMoving && !isSad && !isHappy && currentState != cubeState.determined) { currentState = cubeState.moving; } // Else the cube is Idle else if (!globalVariable.isMoving && currentState != cubeState.sleeping && !isSad && !isHappy && currentState != cubeState.determined) { currentState = cubeState.idle; } // If transitioning between states if (currentState != oldState && currentState != cubeState.sleeping) { setCurrentFace(normalFace); if (oldState == cubeState.idle) { sleepCountdown = 0.0f; } if (oldState == cubeState.sleeping) { fellAsleep = false; resetFallAsleep(); } idleTimeDuration = 0.0f; movingTimeDuration = 0.0f; resetLookLeftAnimation(); resetLookRightAnimation(); idleTimeToLookLeft = false; idleTimeToLookRight = false; idleTimeToBlink = false; } // Check if sad if (globalVariable.totalColorLoss != lostColors && currentState != cubeState.determined) { lostColors = globalVariable.totalColorLoss; currentState = cubeState.sad; isSad = true; } if (sadTimeDurration >= sadTimeMax) { sadTimeDurration = 0.0f; isSad = false; isHappy = false; currentState = cubeState.idle; } // Check if happy if (globalVariable.redSolved && !redSolved && currentState != cubeState.determined) { redSolved = true; currentState = cubeState.happy; isHappy = true; } if (globalVariable.blueSolved && !blueSolved && currentState != cubeState.determined) { blueSolved = true; currentState = cubeState.happy; isHappy = true; } if (globalVariable.yellowSolved && !yellowSolved && currentState != cubeState.determined) { yellowSolved = true; currentState = cubeState.happy; isHappy = true; } if (globalVariable.greenSolved && !greenSolved && currentState != cubeState.determined) { greenSolved = true; currentState = cubeState.happy; isHappy = true; } if (globalVariable.orangeSolved && !orangeSolved && currentState != cubeState.determined) { orangeSolved = true; currentState = cubeState.happy; isHappy = true; } if (globalVariable.purpleSolved && !purpleSolved && currentState != cubeState.determined) { purpleSolved = true; currentState = cubeState.happy; isHappy = true; } if (happyTimeDurration >= happyTimeMax) { happyTimeDurration = 0.0f; isHappy = false; isSad = false; currentState = cubeState.idle; } // Call correct face animation based on the current state switch (currentState) { case cubeState.moving: runMovingState(); break; case cubeState.idle: sleepCountdown += Time.deltaTime; if (sleepCountdown >= sleepLimit) { currentState = cubeState.sleeping; sleepCountdown = 0.0f; } runIdleState(); break; case cubeState.happy: setCurrentFace(happyFace); happyTimeDurration += Time.deltaTime; break; case cubeState.sad: setCurrentFace(sadFace); sadTimeDurration += Time.deltaTime; break; case cubeState.sleeping: fallAsleep(); if (fellAsleep) { playSleepingAnimation(); } break; case cubeState.determined: runDeterminedState(); break; case cubeState.endOfLevel: break; default: Debug.Log("'" + currentState + "' is not a valid cube face state."); break; } if (globalVariable.endLevel && !endOfLevelReached) { showFace(false); endOfLevelReached = true; currentState = cubeState.endOfLevel; } }
void Start() { currentState = cubeState.idle; endOfLevelReached = false; cubeFace = transform.Find("face"); // Blinking blinkTimeDuration = 0.0f; blinkTimeMax = 0.01f; blinkIndex = 0; oldBlinkIndex = 0; playBlinkForward = true; blinkingPlayed = false; // Look Left lookLeftTimeDuration = 0.0f; lookLeftTimeMax = 0.02f; lookLeftIndex = 0; oldLookLeftIndex = 0; playLookLeftForward = true; lookLeftPlayed = false; longLeftCount = 40; startLeftHold = false; // Look Right lookRightTimeDuration = 0.0f; lookRightTimeMax = 0.02f; lookRightIndex = 0; oldLookRightIndex = 0; playLookRightForward = true; lookRightPlayed = false; longRightCount = 40; startRightHold = false; // Sleeping sleepTimeDuration = 0.0f; sleepTimeMax = 0.20f; sleepIndex = 0; oldSleepIndex = 0; playSleepForward = true; sleepCountdown = 0.0f; sleepLimit = 10.5f; fallAsleepTimeDuration = 0.0f; fallAsleepTimeMax = 0.08f; fallAsleepIndex = 0; oldFallAsleepIndex = 0; fellAsleep = false; // Happy happyTimeDurration = 0.0f; happyTimeMax = 2.0f; isHappy = false; redSolved = false; blueSolved = false; yellowSolved = false; greenSolved = false; orangeSolved = false; purpleSolved = false; // Sad sadTimeDurration = 0.0f; sadTimeMax = 2.0f; isSad = false; lostColors = 0; // Moving movingTimeDuration = 0.0f; movingTimeMax = 2.0f; movingTimeToBlink = false; // Idle idleTimeDuration = 0.0f; idleTimeMax = 3.0f; idleTimeToBlink = false; idleTimeToLookLeft = false; idleTimeToLookRight = false; blinking = new List <Texture>(); determinedBlink = new List <Texture>(); lookLeft = new List <Texture>(); lookRight = new List <Texture>(); sleeping = new List <Texture>(); loadTextures(); showFace(true); if (Application.loadedLevelName == "7-1") { setCurrentFace(determinedFace); currentState = cubeState.determined; } }