还剩1页未读,继续阅读
文本内容:
模拟手柄拿枪瞄准及射箭瞄准Unity HTC
一、新建场景
二、创建命名为加刚体,去选(是否使用重力,勾上即是使用重Cube,Cube_Ctrol UseGravity:力)不能勾选(是否是运动学专业的解释是激活时,物体不再受物理引擎驱Is Kinematic动,而只能通过变换来操作一般此选项用于,需要向其他刚体产生作用,自己本身也需要通过变换进行运动的情况)
三、在下创建一拉长,Cube_Ctrol Cube,模拟枪管或箭体Gizmos▼三Hierarchy+▼AllG SampleScenee
⑦Main CameraDirectionalLight
⑦Sphere
⑦Sphere.B▼・Cube.CtrolCubG
四、创建两个小球,分别命名为(模拟左手手柄);(模拟右手手柄)
五、Sphere_F Sphere_B在(模拟右手手柄)上添加如下脚本Sphere_Busing System.Collections;using System.Collections.Generic;using UnityEngine;public classMyControl:MonoBehaviour public GameObject sphere_f;public GameObjectsphere_b;publicGameObjecttest;private boollook=false;private GameObjectcollidingObject;private GameObjectobjectHand;FixedJoint joint;void SetCollidingObjectCollidercolif collidingObject||Icol.GetComponent Rigidbodyreturn;}collidingObject=col.gameObject;GrabObject;void GrabObjectobjectHand=collidingObject;collidingObject=null;look=true;objectHand.GetComponentTransform.positionsphere_b.GetComponentTransform.position;objectHand.GetComponentTransform.LookAtsphere_f.GetComponentTransform;joint=AddFixedJoint;joint.connected Body=gameObject.GetComponentRigidbody;public voidOnCollisionEnterCollision collisionSetCollidingObjectcollision.collider;public voidOnCollisionStayCollision collisionSetCollidingObjectcollision.collider;FixedJoint AddFixedJointjoint=objectHand.AddComponentFixedJoint;joint.breakForce=20000;joint.breakTorque=20000;return joint;//Start iscalled beforethe firstframe updatevoid Start〃Update iscalled onceper framevoidUpdateiflookobjectHand.GetComponentTransform.LookAtsphere_f.GetComponentTransform;}
六、运行,即可模拟枪瞄准及射箭瞄准。
个人认证
优秀文档
获得点赞 0