void FixedUpdate() { if (!currentAnimator.GetBool("IsDead")) { float currentAxes = Input.GetAxis("Horizontal"); if (currentAxes == 0f) { currentAnimator.SetBool("IsWalking", false); } else { currentAnimator.SetBool("IsWalking", true); } if (Jumping) { currentAnimator.SetBool("IsWalking", false); } Vector3 positionToSet = new Vector3(); positionToSet.x = (Speed * currentAxes) * Time.fixedDeltaTime; transform.position = transform.position + positionToSet; LookDirector newLook = LookDirector.Left; if (positionToSet.x > 0) { newLook = LookDirector.Right; } else if (positionToSet.x < 0) { newLook = LookDirector.Left; } else { newLook = currentLook; } if (currentLook != newLook && !currentAnimator.GetBool("Attack")) { Vector3 scaleFactor = new Vector3(-transform.localScale.x, 1, 1); transform.localScale = scaleFactor; currentLook = newLook; } //Jump if (Input.GetKey(KeyCode.Space) && !Jumping) { Jumping = true; var rigidbody = GetComponent <Rigidbody2D>(); rigidbody.AddRelativeForce(new Vector2(1, JumpStrength), ForceMode2D.Impulse); } } }
void Start() { currentAnimator = GetComponent <Animator>(); currentLook = LookDirector.Left; Jumping = false; if (Crystal != null) { var CrystalClass = Crystal.GetComponent <Crystal>(); if (CrystalClass != null) { CrystalClass.CrystalDestroyed += OnCrystalDestroyed; } } }