unity 通过按键(鼠标左键)生成一个物体 用C#怎么写
顺便放上我写的,有问题,求指正if(Input.GetMouseButtonDown(0)){GameObjectnewobject=GameObject.Find("p...
顺便放上我写的,有问题,求指正
if (Input.GetMouseButtonDown(0)) {
GameObject newobject = GameObject.Find("prefebs/Sphere"); //这里返回的是null
print(newobject);
Vector3 a = transform.position;
newobject.transform.localPosition.Set(a.x,a.y,a.z);
//Transform n = Instantiate(newobject.transform,transform.position,transform.rotation);
Vector3 fwd = transform.TransformDirection(Vector3.forward);
newobject.transform.rigidbody.AddForce(fwd*2800); 展开
if (Input.GetMouseButtonDown(0)) {
GameObject newobject = GameObject.Find("prefebs/Sphere"); //这里返回的是null
print(newobject);
Vector3 a = transform.position;
newobject.transform.localPosition.Set(a.x,a.y,a.z);
//Transform n = Instantiate(newobject.transform,transform.position,transform.rotation);
Vector3 fwd = transform.TransformDirection(Vector3.forward);
newobject.transform.rigidbody.AddForce(fwd*2800); 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询