public void Ground_Update() { PlayerAnim currentAnim = PlayerAnim.Idle; if (hInput != 0) { currentAnim = this.objectBeingCarried ? PlayerAnim.Carry_Walk : PlayerAnim.Walk; } else { currentAnim = this.objectBeingCarried ? PlayerAnim.Carry_Idle : PlayerAnim.Idle; } if (!animator.IsPlaying(animations[currentAnim])) { PlayAnim(currentAnim); } //END ANIMATION STUFF if (objectBeingCarried) { HandleObjectThrow(); } else { CheckGrabs(); } this.currentSpeed = this.speed; if (Sinput.GetButtonDown("Jump")) { SfxManager.instance.PlaySound(SoundType.JUMP); Squash(0.05f).Then(() => { Stretch(); velocity.y = jumpSpeed; }); } if (Sinput.GetButtonDown("Down")) { if (groundCollider.CompareTag("OneWay")) { transform.position += Vector3.down * 0.5f; } } this.currentGravityModifier = this.gravityModifier; //STATE CHANGES if (!grounded) { fsm.ChangeState(PlayerState.Air); } HandleLeftRightMovement(); }
// Update is called once per frame void Update() { // If the animation has finished playing, destroy the object if (m_spriteAnim.IsPlaying() == false) { Destroy(gameObject); } }
// Update is called once per frame void Update() { // Create a flag to set if we should destroy this effect bool shouldDestroy = false; if (m_destroyAfterTime > 0) { // Update timer and destroy after time's up m_timer += Time.deltaTime; if (m_timer >= m_destroyAfterTime) { shouldDestroy = true; } } if (m_destroyOnAnimEnd) { // Cache anim component if (m_anim == null) { m_anim = GetComponent <SpriteAnim>(); } // Check if animation has finished playing, and destroy if it has if (m_anim != null && m_anim.IsPlaying() == false) { shouldDestroy = true; } } // Apply gravity m_velocity += Vector3.down * m_gravity * Time.deltaTime; // Apply velocity transform.position += m_velocity * Time.deltaTime; // Face direction if (m_faceDirection) { transform.rotation = Quaternion.FromToRotation(Vector2.right, m_velocity.normalized); } // Destroy if the flag is set if (shouldDestroy) { foreach (GameObject toSpawn in m_spawnOnDestroy) { Instantiate(toSpawn, transform.position, transform.rotation); } Destroy(gameObject); } }
void Update() { // Store the sprite anim component if we haven't already if (m_anim == null) { m_anim = GetComponent <SpriteAnim>(); } // If we're currently shooting, don't do anything else if (m_anim.IsPlaying(m_shoot)) { return; } // Handle movement // Check if we're pressing left/right, and set a direction variable if we are float direction = 0; if (Input.GetKey(KeyCode.LeftArrow)) { direction = -1; } if (Input.GetKey(KeyCode.RightArrow)) { direction = 1; } if (direction == 0) { // If there's no direction pressed, return to the idle animation if (m_anim.Clip != m_idle) // (check we're not already in the animation first though) { m_anim.Play(m_idle); } } else { // If direction is set, play the run animation (after checking we're not already playing it) if (m_anim.Clip != m_run) { m_anim.Play(m_run); } // Move the character in the chosen direction transform.Translate(new Vector3(direction * m_speed * Time.deltaTime, 0, 0)); if (transform.localScale.x != direction) { transform.localScale = new Vector3(direction, 1, 1); } } // Shooting stuff! // Choose weapon with the '1' or '2' keys if (Input.GetKeyDown(KeyCode.Alpha1)) { GetComponentInChildren <PlayRandomAnim>().SetClip(0); } if (Input.GetKeyDown(KeyCode.Alpha2)) { GetComponentInChildren <PlayRandomAnim>().SetClip(1); } // Start shooting animation with the spacebar if (Input.GetKeyDown(KeyCode.Space)) { m_anim.Play(m_shoot); } }