Created
March 27, 2017 05:21
-
-
Save Tachibana446/1768898e4b5ebe49e50ef5190ef38e98 to your computer and use it in GitHub Desktop.
Unity Player Oparation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class Operatable : MonoBehaviour | |
{ | |
public float speed = 5.0f; | |
private float jumpSpeed = 12.0f; | |
public float horizontal = 0, vertical = 0; | |
private Rigidbody2D rb2D; | |
private Transform tr; | |
/// <summary> | |
/// 現在右向きか | |
/// </summary> | |
private bool isRight = true; | |
// Use this for initialization | |
void Start() | |
{ | |
rb2D = GetComponent<Rigidbody2D>(); | |
tr = GetComponent<Transform>(); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
horizontal = Input.GetAxis("Horizontal"); | |
vertical = Input.GetAxis("Vertical"); | |
if (horizontal > 0.5) | |
{ | |
rb2D.velocity = new Vector2(speed, rb2D.velocity.y); | |
tr.rotation = new Quaternion(tr.rotation.x, 180, tr.rotation.z, tr.rotation.w); | |
isRight = true; | |
} | |
else if (horizontal < -0.5) | |
{ | |
rb2D.velocity = new Vector2(speed * -1, rb2D.velocity.y); | |
tr.rotation = new Quaternion(tr.rotation.x, 0, tr.rotation.z, tr.rotation.w); | |
isRight = false; | |
} | |
if (Input.GetButtonDown("Jump")) | |
{ | |
rb2D.velocity = new Vector2(rb2D.velocity.x, jumpSpeed); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment