- Home /
Car MultiTouch Controls
Hi guys, i have found a problem with my code recently, i'm developing a racing game and i need help with the following situation:
i have 4 scripts to control the car (foward, back, left, right) each one is attached to a different GuiTexture.
Everything works like a charm except for one thing, i can only turn my car if i'm already touch the screen wich makes impossible to turn without accelerate or brake, i really need help
i want the car to be able to turn without accelerating or braking
here's the 4 codes
forward.js function Update() {
if(Input.touchCount > 0)
{
var touch: Touch = Input.GetTouch(0);
if((touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position)
))
{
TouchControls.vertical = 1.0;
}
else if (touch.phase == TouchPhase.Ended)
{
TouchControls.vertical = 0.0;
}
}
}
back.js
function Update() {
if(Input.touchCount > 0)
{
var touch: Touch = Input.GetTouch(0);
if(touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position))
{
TouchControls.vertical = -1.0;
}
else if (touch.phase == TouchPhase.Ended && guiTexture.HitTest(touch.position))
{
TouchControls.vertical = 0.0;
}
}
}
left.js
function Update() {
if(Input.touchCount > 0)
{
var touch: Touch;
touch = Input.GetTouch(1);
if(touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position))
{
TouchControls.horizontal = -1.0;
}
else if (touch.phase == TouchPhase.Ended)
{
TouchControls.horizontal = 0.0;
}
}
}
right.js
function Update() {
if(Input.touchCount > 0)
{
var touch: Touch;
touch = Input.GetTouch(1);
if(touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position))
{
TouchControls.horizontal = 1.0;
}
else if (touch.phase == TouchPhase.Ended)
{
TouchControls.horizontal = 0.0;
}
}
}
any help will be really appreciated :)
Your answer
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Touch dont work 1 Answer
Unity 5 sample project files and scenes missing after opening Unity 4 0 Answers
Touch Follow 3d. 1 Answer