Как сделать кнопки для управления (влево, вправо)?

Программирование для iPhone & Android

Как сделать кнопки для управления (влево, вправо)?

Сообщение Alex20 13 дек 2017, 21:25

Всем привет. Хотел спросить, как реализовать управление?
Для ПК оно выглядит так:
using UnityEngine;

public class PlayerMovement : MonoBehaviour {

// This is a reference to the Rigidbody component called "rb"
public Rigidbody rb;

public float forwardForce = 2000f; // Variable that determines the forward force
public float sidewaysForce = 500f; // Variable that determines the sideways force

// We marked this as "Fixed"Update because we
// are using it to mess with physics.
void FixedUpdate ()
{
// Add a forward force
rb.AddForce(0, 0, forwardForce * Time.deltaTime);

if (Input.GetKey("d")) // If the player is pressing the "d" key
{
// Add a force to the right
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}

if (Input.GetKey("a")) // If the player is pressing the "a" key
{
// Add a force to the left
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}

if (rb.position.y < -3f)
{
FindObjectOfType<GameManager>().EndGame();
}
}
}
Что нужно изменить в скрипте, чтобы потом можно было на Image повесить и сделать его кнопкой?
Alex20
UNец
 
Сообщения: 1
Зарегистрирован: 13 дек 2017, 21:07

Вернуться в iPhone & Android

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 3