Question by
$$anonymous$$ · Dec 27, 2018 at 04:14 PM ·
c#unity 52d
Smooth touch movement on axis only while going up?
I'm new to Unity and c#. I'm creating a project for mobile phones. I want to move the jet Axis position only by touching left and right while the Jet is going up
This code works but it slows the screen and jet.
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
switch (touch.phase)
{
case TouchPhase.Began:
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
//side to side movement
if (touch.position.x < Screen.width / 2)
rb.velocity = new Vector2(- 2f, transform.position.y);
if (touch.position.x > Screen.width / 2)
rb.velocity = new Vector2(+ 2f, transform.position.y);
}
break;
case TouchPhase.Ended:
rb.velocity = new Vector2(0f, 0f);
break;
}
The Jet have Addforce so the jet slows down when ever I touch left and right.
Jet code:
switch (JetOn)
{
case true:
StartCoroutine(BurnFuel());
rb.AddForce(new Vector2(0f, JumpForce), ForceMode2D.Force);
break;
case false:
rb.AddForce(new Vector2(0f, 0f), ForceMode2D.Force);
break;
}
,
Comment
Your answer
Follow this Question
Related Questions
Trouble with directing launched projectiles in Unity 2D 0 Answers
Can't get object to destroy itself on collision. 0 Answers
Vectrocity VectorLine Method not Making Multiple Points Line With List 1 Answer
Creating dynamically moving buttons/GUI objects. 1 Answer
Trouble with controlling the direction of projectiles with C# code 1 Answer