Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private var characterAnimator : Animator;
- var speed : float = 3;
- var grounded : boolean = false;
- var jumpHeight : int;
- var isKinematic : boolean = false;
- function OnTriggerEnter2D(collienter : Collider2D) {
- if(gameObject.tag == "Player")
- {
- grounded = true;
- rigidbody2D.isKinematic = true;
- }
- }
- function OnTriggerExit2D(collienter : Collider2D) {
- if(gameObject.tag == "Player")
- {
- grounded = false;
- rigidbody2D.isKinematic = false;
- }
- }
- function Awake() {
- characterAnimator = gameObject.GetComponent("Animator");
- }
- function Start () {
- }
- function Update () {
- if (Input.GetKey(KeyCode.A)) {
- gameObject.transform.position.x -= speed * Time.deltaTime;
- gameObject.transform.rotation.y = 180;
- characterAnimator.SetBool("walk", true);
- }else if (Input.GetKey(KeyCode.D)) {
- gameObject.transform.position.x += speed * Time.deltaTime;
- gameObject.transform.rotation.y = 0;
- characterAnimator.SetBool("walk", true);
- }else {
- gameObject.transform.position.x += 0 * Time.deltaTime;
- characterAnimator.SetBool("walk", false);
- }
- if (Input.GetKey(KeyCode.Space)) {
- if(grounded) {
- rigidbody2D.isKinematic = false;
- jumpHeight = 3 * 250;
- gameObject.rigidbody2D.AddForce(Vector2.up * jumpHeight);
- grounded = false;
- }
- }
- }
- /*function OnTriggerExit(colliexit : Collider) {
- if(colliexit.gameObject.tag == "Player")
- {
- rigidbody2D.isKinematic = false;
- }
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement