Nie mogę klikać. Gra będzie na Androida a przycisk jest od tego że postać się porusza gdy trzymamy przycisk. Mógłbym zrobić większy ruch i dać do OnClick ale wtedy to będzie niewygodne.
Na komputerze trzymam strzałkę i porusza się
Chciałbym by było tak samo z przyciskiem :(
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;
}
}
Przyciski wywołują funkcje MoveLeft() i MoveRight()