- Home /
Question by
Oliversgame · Aug 26, 2019 at 07:29 AM ·
transforminputpositiontranslate
If click go up else pingpong movement (2d)
I have a script which is kind of work: When i click, the Player, start going up and when i release, start doing the back and forth movement. The problem is when i release the mouse button the player position changing in x-axis every time. It's looks like the pingpong movement never stops, and when stop going up, join back where it should to be. I hope its understandable.
Heres my script:
void Update() {
if (Input.GetMouseButton(0))
{
float translation = 6f;
translation *= Time.deltaTime;
transform.Translate(0, translation, 0);
} else
{
float min = -2.3f;
float max = +2.3f;
transform.position = new Vector3(Mathf.PingPong(Time.time * 6, max - min) + min, transform.position.y, transform.position.z);
} }
Somebody can suggest an alternative method or fix this?
Comment