1
Banda Quentina / Gothic: Banda Quentina - dyskusja ogólna
« dnia: 2017-01-09, 13:04 »
Może dalej pije.
Ta sekcja pozwala Ci zobaczyć wszystkie wiadomości wysłane przez tego użytkownika. Zwróć uwagę, że możesz widzieć tylko wiadomości wysłane w działach do których masz aktualnie dostęp.
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour
{
public int Speed = 7;
public int JumpHeight = 3;
bool grounded;
void Update ()
{
if ((Input.GetKeyUp (KeyCode.UpArrow) || Input.GetKeyUp (KeyCode.W)) && grounded == true)
{
Jump ();
}
if ((Input.GetKey (KeyCode.LeftArrow)) || (Input.GetKey (KeyCode.A)))
{
MoveLeft ();
}
if ((Input.GetKey (KeyCode.RightArrow)) || (Input.GetKey (KeyCode.D)))
{
MoveRight ();
}
}
void Jump ()
{
this.GetComponent<Rigidbody2D> ().AddForce (Vector2.up * JumpHeight * 100);
}
void MoveLeft ()
{
this.GetComponent<Rigidbody2D> ().AddForce (Vector2.left * Speed);
}
void MoveRight ()
{
this.GetComponent<Rigidbody2D> ().AddForce (Vector2.right * Speed);
}
void OnCollisionEnter2D(Collision2D coll)
{
grounded = true;
}
void OnCollisionExit2D(Collision2D coll)
{
grounded = false;
}
}