Skip to content

Instantly share code, notes, and snippets.

@Carwashh
Created November 22, 2020 10:53
Show Gist options
  • Save Carwashh/aa138e2487d7324407b7ff603996577f to your computer and use it in GitHub Desktop.
Save Carwashh/aa138e2487d7324407b7ff603996577f to your computer and use it in GitHub Desktop.
Example class of how to use AVC with touchscreen input
using e23.VehicleController;
using UnityEngine;
using UnityEngine.EventSystems;
public class ExampleTouchScreen : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
[SerializeField] VehicleBehaviour vehicleBehaviour;
[SerializeField] bool accelerate;
[SerializeField] bool brake;
[SerializeField] bool steerLeft;
[SerializeField] bool steerRight;
private bool doAction = false;
public VehicleBehaviour VehicleBehaviour {
get { return vehicleBehaviour; }
set { vehicleBehaviour = value; }
}
public void OnPointerDown(PointerEventData eventData)
{
doAction = true;
}
public void OnPointerUp(PointerEventData eventData)
{
doAction = false;
}
private void Update()
{
if (doAction)
{
// Acceleration
if (accelerate) { VehicleBehaviour.ControlAcceleration(); }
if (brake) { VehicleBehaviour.ControlBrake(); }
// Steering
if (steerLeft) { VehicleBehaviour.ControlTurning(-1); }
if (steerRight) { VehicleBehaviour.ControlTurning(1); }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment