Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/7e5993c4c593cb54574f to your computer and use it in GitHub Desktop.
Save tsubaki/7e5993c4c593cb54574f to your computer and use it in GitHub Desktop.
接触したら只管ジャンプするやつ
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Rigidbody2D))]
public class Jump : MonoBehaviour {
[SerializeField, HideInInspector]
Rigidbody2D rigidbody = null;
void Reset()
{
rigidbody = GetComponent<Rigidbody2D>();
}
void Update ()
{
var velocity = rigidbody.velocity;
velocity.x = Input.GetAxis("Horizontal") * 5;
rigidbody.velocity = velocity;
}
void OnCollisionEnter2D(Collision2D coll)
{
var velocity = rigidbody.velocity;
if(velocity.y <= 0 ){
velocity.y = 6;
rigidbody.velocity = velocity;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment