Skip to content

Instantly share code, notes, and snippets.

@dariusf
Last active February 2, 2016 04:30
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 dariusf/3c62e90cee44e7126b98 to your computer and use it in GitHub Desktop.
Save dariusf/3c62e90cee44e7126b98 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class PlayerControl : MonoBehaviour {
public float moveSpeed;
public float jumpForce;
private Rigidbody2D myRigidbody;
// public bool grounded;
// public LayerMask whatIsGround;
public bool floating;
public bool goDown;
public bool ready;
private CircleCollider2D myCollider;
void Start () {
myRigidbody = GetComponent<Rigidbody2D> ();
myCollider = GetComponent<CircleCollider2D> ();
}
void Update () {
// grounded = Physics2D.IsTouchingLayers (myCollider, whatIsGround);
myRigidbody.velocity = new Vector2 (moveSpeed, myRigidbody.velocity.y);
if (Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown (0)) {
if (goDown) {
myRigidbody.velocity = new Vector2 (myRigidbody.velocity.x, -jumpForce);
} else {
myRigidbody.velocity = new Vector2 (myRigidbody.velocity.x, jumpForce);
}
goDown = !goDown;
// if (floating) {
// myRigidbody.gravityScale = 5;
// floating = false;
// }
}
// if (Mathf.Approximately (myRigidbody.velocity.y, 0)) {
// myRigidbody.gravityScale = 0;
// floating = true;
// }
}
void OnCollisionEnter2D (Collision2D col) {
myRigidbody.velocity = Vector3.zero;
//Code for restart level when touching wall..
// if(col.gameObject.name == "wall")
// {
// Application.LoadLevel (Application.loadedLevel);
// }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment