// Update is called once per frame private void Update() { //return key pressed? if (Input.GetKeyDown(KeyCode.Escape)) { p_nextScene = true; p_returnScene = true; } //check touch controls if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); //save the touch and swipe positions switch (touch.phase) { case TouchPhase.Began: p_startPos = touch.position; break; case TouchPhase.Moved: p_direction = touch.position - p_startPos; break; case TouchPhase.Ended: p_direction.x = 0; p_direction.y = 0; break; } } //if the player swiped for a certain distance, start to load new map if (Mathf.Abs(p_direction.x) > p_triggerDistance) { //dont change map to frequently if (Time.time - p_lastLevelChange > 0.3f) { p_lastLevelChange = Time.time; //change to next or previous map and set animatin accordingly if (p_direction.x < 0) { MemoryCard.AddToSelectedLevel(+1); p_mapGoToThisPosition = p_mapLeftPosition; } else { MemoryCard.AddToSelectedLevel(-1); p_mapGoToThisPosition = p_mapRightPosition; } } } //change scene once the camera finished animation if (p_nextScene && m_camera.transform.position.x < -19) { if (p_returnScene) { MemoryCard.LoadMenu(); } else { MemoryCard.LoadSelectedLevel(); } } //animate AnimateScreenTransitions(); AnimateMapTransition(); AnimateScreen(); //if the map has finished animation, load a new map if (p_currentMapPreview.transform.position.x < -19 || p_currentMapPreview.transform.position.x > 19) { LoadPreview(MemoryCard.GetSelectedLevelIndex()); //load currently selected level } }
// Update is called once per frame private void Update() { //return key pressed? if (Input.GetKeyDown(KeyCode.Escape)) { p_nextScene = true; p_returnScreen = true; } //turtle animation float sinUpDown = Mathf.Sin(Time.time * 3); float sinLeftRight = Mathf.Sin(Time.time * 1); m_turtle.transform.position = p_turtleOriginalPosition; m_turtle.transform.Translate(new Vector3(sinLeftRight, sinUpDown, 0)); m_turtle.transform.Rotate(new Vector3(0, 1, 0), Time.deltaTime * m_rotationSpeed, Space.World); m_turtle.transform.Rotate(new Vector3(1, 0, 0), sinUpDown * 0.5f, Space.World); //button animation float sinButtonScale = Mathf.Sin(Time.time * 3.1f); m_continueButton.transform.localScale = new Vector3(1, 1, 1) * (sinButtonScale * sinButtonScale * 0.05f + 0.4475f); //camera animation if (p_nextScene) { m_camera.transform.position = Vector3.SmoothDamp(m_camera.transform.position, p_cameraEnd, ref p_cameraVelocity, m_turtleSmoothTime); //animate buttons fly out m_contButtonImage.transform.localPosition = Vector3.SmoothDamp(m_contButtonImage.transform.localPosition, p_contButtonOutside, ref p_contButtonVelocity, m_buttonSmoothTime); m_lvlselectButtonImage.transform.localPosition = Vector3.SmoothDamp(m_lvlselectButtonImage.transform.localPosition, p_lvlselectButtonOutside, ref p_lvlselectButtonVelocity, m_buttonSmoothTime); if (m_camera.transform.position.y < -15) { //choose wich scene to load if (p_returnScreen) { MemoryCard.LoadSplash(); } else if (p_selectLevel) { MemoryCard.LoadLevelSelection(); } else { MemoryCard.LoadSelectedLevel(); } } } else { //animate camera m_camera.transform.position = Vector3.SmoothDamp(m_camera.transform.position, new Vector3(0, 0, -10), ref p_cameraVelocity, m_turtleSmoothTime); //animate buttons to fly in m_contButtonImage.transform.localPosition = Vector3.SmoothDamp(m_contButtonImage.transform.localPosition, p_contButtonInside, ref p_contButtonVelocity, m_buttonSmoothTime); m_lvlselectButtonImage.transform.localPosition = Vector3.SmoothDamp(m_lvlselectButtonImage.transform.localPosition, p_lvlselectButtonInside, ref p_lvlselectButtonVelocity, m_buttonSmoothTime); //animate buttons to wobble ScaleAnimateObject(0.6f, 0.6f, m_contButtonImage); ScaleAnimateObject(0.8f, 0.8f, m_lvlselectButtonImage); } }