【发布时间】:2018-12-27 18:56:49
【问题描述】:
我是 Unity 和 c# 的新手。我正在为手机创建一个项目。我只想在 Jet 上升时通过左右触摸来移动 jet Axis 位置
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;
}
Jet 具有 Addforce,因此当我左右触摸时,Jet 会减慢速度。
喷射代码:
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;
}
【问题讨论】:
标签: c# unity3d touch game-physics