当前位置: 首页 > 后端技术 > Python

Unity3d游戏常用API函数

时间:2023-03-26 15:07:36 Python

野子电竞数据官网改版https://www.xxe.io/全新登场1.实例化原型:publicstaticObjectInstantiate(Objectoriginal,Vector3position,Quaternionrotation);功能:生成对象实例。可用于生成新的子弹/炮弹/物体,也可用于刷新敌人参数传递,以上是最常用的版本3)获取新生成物体的属性/组件时,需要定义用于访问的变量存储,如:GameObjectp=Instantiate();刚体m=p.GetComponent();2.位移函数(1)transform.Translate原型:publicvoidTranslate(Vector3translation,SpacerelativeTo=Space.Self);功能:使某物在三维世界中“瞬移”示例:transform.Translate(newVector3(0,0,1)moveSpeedTime.deltaTime);注意:参数为向量,必须有方向,加速度变量可以乘以参数(2)velocity(刚体)原型:publicVector3velocity;例子:r.velocity=shootPoint.forward*shootPower;注意:指定刚体的速度,也是一个向量,适用物理定律3.transform.RotateAround原型:publicvoidRotateAround(Vector3point,Vector3axis,floatangle);功能:使某物围绕另一个物体的哪个轴旋转示例:transform.RotateAround(center.GetComponent().position,Vector3.up,-70*Time.deltaTime);使transform以704.Physics.OverlapSphere的速度绕中心y轴旋转原型:publicstaticCollider[]OverlapSphere(Vector3position,floatradius,intlayerMask=AllLayers,QueryTriggerInteractionqueryTriggerInteraction=QueryTriggerInteraction.UseGlobal);作用:用于捕获一个以position为圆心的圆圈内的所有碰撞器,返回值会是一个碰撞器数组,一般用于在OnCollisionEnter()触发碰撞检测时获取碰撞器(如手雷爆炸等)。示例:Collider[]cols=Physics.OverlapSphere(transform.position,explosionRadius);5.Rigidbody.AddExplosionForce原型:publicvoidAddForce(Vector3force,ForceModemode=ForceMode.Force);功能:在某一点添加力场,可用于爆炸等场景模拟实例:rb.AddExplosionForce(explosionPower,transform.position,explosionRadius);在rb上添加一个力作为explosionPower,它的位置作为它自己6.Destory原型:publicstaticvoidDestroy(Objectobj,floatt=0.0F);功能:删除场景中的一个物体实例:Destroy(gameObject);//删除gameObjectDestroy(se,delayClearExplosion);//删除se在delayClearExplosion秒后更新事件函数:事件函数概述:voidReset():当脚本附加到GameObject或点击面板中脚本的重置按钮时执行voidFixedUpdate():修复Frameratecall,可能会出现一帧调用多次,用于motion相关的代码控制。Time类captureFramerate:将游戏速度减慢到(1/value)时间,方便游戏截图