// Start is called before the first frame update void Start() { myRigidBody = GetComponent <Rigidbody2D>(); animator = GetComponent <Animator>(); myFeet = GetComponent <BoxCollider2D>(); island = FindObjectOfType <MovingIsland>(); }
// Update is called once per frame void FixedUpdate() { if (!blocked) { Vector2 velocity = rb.velocity; float movex = Input.GetAxis("Horizontal"); velocity.x = movex * speed; if (velocity.x <= 1 && velocity.x >= 0) { velocity.x = touchMove * speed; } //Flip the player if (velocity.x < 0) { transform.localScale = new Vector3(-.3f, .3f, .3f); } else { transform.localScale = new Vector3(.3f, .3f, .3f); } //Jumping if (jumpEnabled && (Input.GetKey(KeyCode.Space) || touchJump)) { velocity.y = jumpheight; animator.SetFloat("Speed", .2f); touchJump = false; animator.SetBool("Jump", true); soundManager.PlaySound(SoundManager.SoundType.PlayerJump); } if (Mathf.Abs(velocity.x) > 0) { // Start walking. animator.SetFloat("Speed", speed); } else { // Stop walking. animator.SetFloat("Speed", 0f); } // Moving platforms. if (movingPlatform != null) { MovingIsland movIsland = movingPlatform.GetComponent <MovingIsland>(); if (movIsland != null) { velocity.x += movIsland.GetVelocity().x; if (movIsland.GetVelocity().y < 0) { velocity.y += movIsland.GetVelocity().y; } } } rb.velocity = velocity; // Debug.Log("Velocity=" + rb.velocity); } else { // Stop walking. animator.SetFloat("Speed", 0f); rb.velocity = new Vector2(0, 0); } }