// Update is called once per frame void Update() { if (!isHop) { timeCount += Time.deltaTime; rb2d.constraints = RigidbodyConstraints2D.FreezePositionX; if (timeCount > stopTime) { isHop = true; timeCount = 0; anim.SetBool("isHop", true); rb2d.constraints = RigidbodyConstraints2D.None; } rb2d.constraints = RigidbodyConstraints2D.FreezeRotation; } else { float xSpeed = wallReflection.XSpeed(); timeCount += Time.deltaTime; Hop(timeCount, xSpeed); float diffYPos = prevYPos - transform.localPosition.y; if (diffYPos > 0 && Mathf.Abs(diffYPos) < diffPosYThreshold) { isHop = false; timeCount = 0; anim.SetBool("isHop", false); } prevYPos = transform.localPosition.y; } }
// Update is called once per frame void Update() { float xSpeed = wallReflection.XSpeed(); rb2d.velocity = new Vector2(xSpeed, rb2d.velocity.y); }