嗨,我正在尝试创建一个球体并朝我从屏幕中间看的方向发射它。但是我目前从中间发射,但总是在相同的方向和高度。tanx 寻求帮助。
#pragma strict
private var globe:GameObject;
var globeMaterial:Material;
private var shootIndex:boolean;
function Start () {
}
function Update () {
if(Input.GetMouseButtonDown(0))
{
if (shootIndex==false){
globe=GameObject.CreatePrimitive(PrimitiveType.Sphere);
globe.renderer.material=globeMaterial;
globe.AddComponent(Light);
globe.light.color=Color.blue;
globe.AddComponent(Rigidbody);
//globe.transform.position=Camera.main.ScreenToViewportPoint(Input.mousePosition);
globe.transform.position=Camera.main.transform.position;
globe.transform.localScale=Vector3(0.5,0.5,0.5);
globe.rigidbody.AddRelativeForce(Vector3.forward*1000);
shootIndex=true;
}
else if (shootIndex==true){
Destroy(globe);
shootIndex=false;
}
}
}