Wednesday, July 27, 2016

c# - Unity Player Movement Y Axis(Something like Swing Copters)



My Player moves on Y AXIS , but sometimes it doesnt go up but stucks in one place, Script is like in swing copters , when you touch it rotates to another side but its on X Axis , i took and made it on Y axis , but it doesnt work properly , player sometimes doesnt turn around and go up or back Please help out , sorry for bad english


void MovePlayerOnYAxis()
{

foreach (Touch touch in Input.touches)
{


moveL = !moveL;


if (moveL)
{

transform.localScale = new Vector3(1, -1, 1);
}
else
{
transform.localScale = new Vector3(1, 1, 1);
}


huongbay = transform.localScale.x;
}
transform.root.Translate(Vector3.up * speed * huongbay * Time.deltaTime);
}

Pre-Fix From @PompeyPaul But Player still doesnt go Down , it now goes only up.


void MovePlayerOnYAxis()
{

foreach (Touch touch in Input.touches)

{

WasTouched = !WasTouched;


if (WasTouched)
{
if (Input.touchCount == 0)
{
WasTouched = false;


transform.localScale = new Vector3(1, 1, 1);
}
}
else
{
if (Input.touchCount > 0)
{
WasTouched = true;
transform.localScale = new Vector3(1,-1, 1);

}

}
huongbay = transform.localScale.y;

}
transform.root.Translate(Vector3.up * speed * huongbay * Time.deltaTime);
}


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...