Hello, I’m new here and in programming and I would like to know how I can improve this script !?
In the test I find it a bit slow! At the time of changing the place image.
My android is the 7.0 = moto g5
And are testing on HVGA 480x800.
thanks for the help!
public class NewBehaviourScript : MonoBehaviour {
public float playX;
public bool tLeft;
public bool tRight;
float Ctela = 240.0f; //screem center
void Start ()
{
tRight = true;
}
// Update is called once per frame
void Update ()
{
if(Input.touchCount > 0)
{
if(Input.GetTouch(0).phase == TouchPhase.Began)
{
//variavel play x recebe o valor referente ao toque do lado direito ou esquerdo.
playX = Input.GetTouch (0).position.x;
/*
* o valor da variavel Ctela; = centro da tela; se refere a metade da tela de 480x854px
* em outro tamanho de tela a variavel Ctela deve ser mudada pela (largura_da_tela / 2)
*
*/
if(playX > Ctela && tRight == true)
{
print ("direita");
transform.Translate(new Vector2(3.0f,0));
tLeft = true;
tRight = false;
}
else if(playX < Ctela && tLeft == true)
{
print ("esquerda");
transform.Translate(new Vector2(-3.0f,0));
tRight = true;
tLeft = false;
}
}
}
}
}