我正在尝试创建一组操作2D游戏对象的按钮,以及人们发布的有关InputManager的所有内容,但我认为这不是我想要做的。我正在寻找将执行以下操作的c#代码:(以及我目前在下面发布的代码)
Update()
或FixedUpdate()
方法检查按钮是否仍然按下。我现在的代码只是将对象移动到ONCE,而不是在此之后注意到其余的点击。
我真的很感谢收到的所有帮助,谢谢。
using UnityEngine;
using System.Collections;
public class fScript : MonoBehaviour {
public GameObject player;
private Rigidbody2D rb;
Vector3 v;
// Use this for initialization
void Start () {
rb = player.gameObject.GetComponent<Rigidbody2D> ();
v = new Vector3 (10, 0, 0);
}
// Update is called once per frame
public void MovePLayer () {
rb.AddForce (v);
Debug.Log ("CLICKED");
}
}
答案 0 :(得分:0)
在这种情况下,您需要尝试使用设置Velocity。速度在下一刻不断减速。如果您每帧都会改变速度,按下按钮时您将获得恒定的速度。 但还有一件事。您需要申请不要OnClick事件!正如我所知,你需要在UI按钮中没有实现的OnPress事件。 尝试使用下一个代码解决此问题:
private bool MouseIsDown;
void OnPointerDown(){
MouseIsDown = true;
}
void OnPointerUp(){
MouseIsDown = false;
}
当MouseIsDown == true; 时,并且在IF体中需要具有固定更新速度的代码