Last active
February 2, 2016 04:30
-
-
Save dariusf/3c62e90cee44e7126b98 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; | |
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