Last active
August 29, 2015 14:24
-
-
Save tsubaki/7e5993c4c593cb54574f to your computer and use it in GitHub Desktop.
接触したら只管ジャンプするやつ
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; | |
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