【发布时间】:2016-12-15 05:13:33
【问题描述】:
我是游戏开发的初学者。我正在开发一个游戏,我有一个球,我想通过触摸来移动它。我希望它像足球比赛一样移动,球可以在触摸的方向移动。
但是,现在它似乎只能朝着前进的方向前进!这是我的代码:
public float ThroughSpped;
public float ArchSpped;
void OnMouseDown() {
distance = Vector3.Distance (transform.position, Camera.main.transform.position);
Dragging = true;
}
public void OnMouseUp()
{
//Instantiate(this) ;
this.GetComponent<Rigidbody> ().useGravity = true;
this.GetComponent<Rigidbody> ().velocity += this.transform.forward*ThroughSpped;
this.GetComponent<Rigidbody> ().velocity += this.transform.up*ArchSpped;
Dragging = false;
}
void DraggingBall()
{
if (Dragging)
{
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
Vector3 raypoint = ray.GetPoint (distance);
transform.position = Vector3.Lerp (this.transform.position, raypoint, Speed * Time.deltaTime);
Destroy(BallPrefabClone, 1f);
}
}
【问题讨论】:
-
你的球只向前移动吗..是不是像扔 pokeball 一样?