当前位置: 首页 > 编程语言 > C#

为什么宇宙飞船撞上盒子碰撞器后他们不回头看?分享

时间:2023-04-10 17:56:11 C#

为什么飞船撞上箱式对撞机后他们不回头?当有对撞机时,我想将飞船转回去。但是他们继续使用开箱即用的碰撞器和地形。使用克隆发出的脚本,我想在撞击时返回:usingSystem;使用统一引擎;使用Random=UnityEngine.Random;使用系统集合;使用System.Collections.Generic;publicclassSphereBuilder:MonoBehaviour{publicGameObjectSpaceShip;游戏对象[]球体;公共浮动移动速度=50;//用于跟踪属性更改privateVector3_extents;私人诠释_sphereCount;私人浮动_sphereSize;//////球体随机放置多远。///公共Vector3范围;//////需要多少个球体。///publicintSphereCount;公共浮动SphereSize;privatevoidStart(){spheres=GameObject.FindGameObjectsWithTag("MySphere");}privatevoidOnValidate(){//防止输入错误值Extents=newVector3(Mathf.Max(0.0f,Extents.x),Mathf.Max(0.0f,Extents.y),Mathf.Max(0.0f,范围.z));SphereCount=Mathf.Max(0,SphereCount);SphereSize=Mathf.Max(0.0f,SphereSize);}privatevoidReset(){Extents=newVector3(250.0f,20.0f,250.0f);球体ereCount=100;球体大小=20.0f;}privatevoidUpdate(){UpdateSpheres();移动船舶();//lastPosition=child.position;}privatevoidMoveShips(){foreach(Transformchildinspheres[0].transform){child.transform.position+=Vector3.forward*Time.deltaTime*moveSpeed;}}privatevoidUpdateSpheres(){if(Extents==_extents&&SphereCount==_sphereCount&&Mathf.Approximately(SphereSize,_sphereSize))返回;//清理varspheres=GameObject.FindGameObjectsWithTag("Sphere");foreach(vartinspheres){if(Application.isEditor){DestroyImmediate(t);}else{销毁(t);}}varwithTag=GameObject.FindWithTag("Terrain");if(withTag==null)thrownewInvalidOperationException("Terrainnotfound");对于(vari=0;i