Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PlayerController : MonoBehaviour {
- public float speed = 1;
- private Rigidbody2D rigidbody;
- private Animator animator;
- private int key;
- public float jumpForce = 240.0f;
- private float walkForce = 20.0f;
- private float MaxWalkSpeed = 10.0f;
- // Use this for initialization
- void Start () {
- rigidbody = GetComponent<Rigidbody2D>();
- animator = GetComponent<Animator>();
- }
- // Update is called once per frame
- void Update () {
- key = 0;
- //ジャンプ
- if (Input.GetKeyDown(KeyCode.Space))
- {
- animator.SetTrigger("JumpTrigger");
- rigidbody.AddForce(transform.up * jumpForce);
- //jump_ = true;
- }
- if(Input.GetKey(KeyCode.RightArrow))
- {
- key = 1;
- }
- if (Input.GetKey(KeyCode.LeftArrow))
- {
- key = -1;
- }
- if ( key != 0)
- {
- transform.localScale = new Vector3(key,1,1);
- }
- float speedx = Mathf.Abs(rigidbody.velocity.x);//ここです。
- //Debug.Log(speedx);
- if(speedx < MaxWalkSpeed)
- {
- rigidbody.AddForce(transform.right * key * walkForce);
- }
- if(rigidbody.velocity.y == 0)
- {
- animator.speed = speedx / 2.0f;
- }
- else
- {
- animator.speed = 1.0f;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement