Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class J_PlayerController_Jumping : MonoBehaviour {
- [SerializeField]
- float moveSpd;
- [SerializeField]
- float jumpPower;
- Rigidbody2D myRigidbody2d;
- SpriteRenderer mySpriteRenderer;
- void Awake(){
- myRigidbody2d = GetComponent<Rigidbody2D> ();
- mySpriteRenderer = GetComponent<SpriteRenderer> ();
- }
- void Update(){
- FlipCharacter ();
- }
- void FixUpdate () {
- Movement ();
- }
- void OnCollisionEnter2D(Collision2D col) {
- myRigidbody2d.velocity = new Vector2 (myRigidbody2d.velocity.x, 0f);
- myRigidbody2d.AddForce (Vector2.up * jumpPower);
- }
- void Movement(){
- myRigidbody2d.AddForce (Vector2.right * Input.GetAxis ("Horizontal") * moveSpd);
- }
- void FlipCharacter(){
- if (Input.GetAxisRaw ("Horizontal") < 0)
- mySpriteRenderer.flipX = true;
- else if (Input.GetAxisRaw ("Horizontal") > 0)
- mySpriteRenderer.flipX = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment