Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Unity Player Oparation
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