// Update is called once per frame void Update() { switch (state) { default: case State.WaitingToStart: if (Input.GetMouseButtonDown(0)) { state = State.Playing; rb.bodyType = RigidbodyType2D.Dynamic; Jump(); OnStartPlaying?.Invoke(this, EventArgs.Empty); } break; case State.Playing: if (Input.GetMouseButtonDown(0)) { Jump(); } break; case State.Dead: break; } }
private IEnumerator PlayingRoutine(float blendingTime) { // blend to the new animation first frame var firstFrame = currentData.frames.FirstOrDefault(); if (firstFrame == null) { yield break; } yield return(BlendTo(blendingTime, firstFrame)); // blending complete - start playing sound player?.Play(); OnStartPlaying?.Invoke(); // play animation do { yield return(PlayAnimation()); }while (isLoop); // move to idle frame var idleFrame = GenerateIdleFrame(); yield return(BlendTo(blendingTime, idleFrame)); // animation complete OnFinishPlaying?.Invoke(); }
private void Update() { switch (state) { default: case State.WaitingToStart: if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.RightArrow)) { state = State.Playing; OscarRigidbody2D.bodyType = RigidbodyType2D.Dynamic; OnStartPlaying?.Invoke(this, EventArgs.Empty); } break; case State.Playing: if (Input.GetKey(KeyCode.LeftArrow)) { MoveLeft(); } else if (Input.GetKey(KeyCode.RightArrow)) { MoveRight(); } else if (Input.touchCount > 0) { MoveByTouch(); } else if (Input.GetKey(KeyCode.Mouse0)) { MoveMouse(); } PreventFallingOffSides(); break; case State.Hit: break; } }
void StartPlaying() { gameState = GameState.Playing; OnStartPlaying?.Invoke(); }