Question by
afgr200304 · Jul 18, 2021 at 02:12 PM ·
inputtouch
Change the value of X between each touch
Hello everyone!!
I am learning C #, help me, I am trying to pass the code that I use to make the keyboard sound but when I use the touch sometimes it stops detecting or increases the value and I already tried it on some devices and the same thing happens and I would like someone to tell me say how I could make it functional without that glitch.
This is the code I use on the PC
private void FixedUpdate()
{
if (Input.GetKey(KeyCode.D))
{
direccion = 5;
}
else if (Input.GetKey(KeyCode.A))
{
direccion = -5;
}
if (run2 == true)
{
gameObject.transform.Translate(direccion * Time.deltaTime, velocidad * Time.deltaTime, 0);
}
This is the code I am trying to use for phones.
private void FixedUpdate()
{
foreach (Touch touch in Input.touches)
if (touch.phase == TouchPhase.Began)
{
direct = true;
if (direct == true)
{
getTouch++;
direct = false;
}
if (getTouch ==1)
{
direccion = 5;
}
else if (getTouch >= 2)
{
direccion = -5;
getTouch = 0;
direct = true;
}
}
if (run2 == true)
{
gameObject.transform.Translate(direccion * Time.deltaTime, velocidad * Time.deltaTime, 0);
}
Comment