Created
November 22, 2020 10:53
-
-
Save Carwashh/aa138e2487d7324407b7ff603996577f to your computer and use it in GitHub Desktop.
Example class of how to use AVC with touchscreen input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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