Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

using UnityEngine;

using System.Collections;

public class Gerak : MonoBehaviour {

// Use this for initialization

public float cepat;

public float lompat;

float gerakVelocity;

bool berpijak = true;

// Update is called once per frame

void Update () {

//lompat

if (Input.GetKeyDown (KeyCode.Space) || Input.GetKeyDown (KeyCode.UpArrow)) {

if (berpijak) {

GetComponent<Rigidbody2D> ().velocity = new Vector2


(GetComponent<Rigidbody2D> ().velocity.x, lompat);

gerakVelocity = 0;

//Bergerak ke kanan ke kiri

if (Input.GetKey (KeyCode.LeftArrow) || Input.GetKey (KeyCode.A)) {


gerakVelocity = -cepat;

if (Input.GetKey (KeyCode.RightArrow) || Input.GetKey (KeyCode.D)) {

gerakVelocity = cepat;

GetComponent<Rigidbody2D> ().velocity = new Vector2 (gerakVelocity,


GetComponent<Rigidbody2D> ().velocity.y);

//Cek Jika Berpijak di tanah

void IyaBerpijak2D()

berpijak = true;

void TidakBerpijak2D ()

berpijak = false;

You might also like