-
until3d基本流程查看全部
-
如何更新逻辑查看全部
-
如何通过脚本驱动游戏查看全部
-
C#和unityscript component查看全部
-
我就截个图查看全部
-
创建了一些地形,比较有用查看全部
-
11122查看全部
-
游戏开发查看全部
-
public float speed;//移动速度 public Rigidbody rb; public Camera camera; public float turningSmoothing = 0.3f; private Vector3 facingDirection ; private Plane plan; void Awake () { //垂直与物体y轴的平面 plan = new Plane (transform.up, new Vector3 (2, transform.position.y, 4)); } void Start () { rb = GetComponent<Rigidbody> (); }查看全部
-
//(系统函数)没daltTime调用一次(通常处理物理运算) void FixedUpdate () { serFaceingDirection (); //使物体朝着鼠标旋转 UpdateRotation (); } //设置旋转的方向(及鼠标在物体运动平面的坐标(x,0,z)) public void serFaceingDirection () { Vector3 mosePosition = transform.TransformPoint (Input.mousePosition); facingDirection = ScreenPointToWorldPointOnPlane (Input.mousePosition, plan, camera); facingDirection.y = transform.position.y; Debug.DrawLine(transform.position,facingDirection); }查看全部
-
//放回射线与平面相交的点 public Vector3 ScreenPointToWorldPointOnPlane (Vector3 screenPoint, Plane plane, Camera camera) { // Set up a ray corresponding to the screen position Ray ray = camera.ScreenPointToRay (screenPoint); // Find out where the ray intersects with the plane float dist=0f; plane.Raycast(ray ,out dist );//射线与平面相交是放回true,并设置dist的值(及焦点与射线源点的距离) Vector3 vect=ray.GetPoint(dist);//放回沿射线距离为dist的点 return vect; }查看全部
-
//更新物体的旋转角度(及刚体的角速度) void UpdateRotation () { // Setup player to face facingDirection, or if that is zero, then the movementDirection Vector3 faceDir = facingDirection; // Make the character rotate towards the target rotation if (faceDir == Vector3.zero) { GetComponent<Rigidbody> ().angularVelocity = Vector3.zero; } else { float rotationAngle = AngleAroundAxis (transform.forward, faceDir, Vector3.up); //设置刚体的角速度 GetComponent<Rigidbody> ().angularVelocity = (Vector3.up * rotationAngle * turningSmoothing); } }查看全部
-
将老师间的人物跟着鼠标旋转的代码整理了下: // The angle between dirA and dirB around axis(向量a,b以轴axis的夹角) static float AngleAroundAxis (Vector3 dirA, Vector3 dirB, Vector3 axis) { // Project A and B onto the plane orthogonal target axis dirA = dirA - Vector3.Project (dirA, axis);//dirA到轴axis的投影(计算dirA投影在垂直于axis轴的平面的向量) dirB = dirB - Vector3.Project (dirB, axis);//dirB到轴axis的投影(计算dirB投影在垂直于axis轴的平面的向量 // Find (positive) angle between A and B float angle = Vector3.Angle (dirA, dirB);//得到鼠标前后两次位置在平面上的转动的角度 // Return angle multiplied with 1 or -1 return angle * (Vector3.Dot (axis, Vector3.Cross (dirA, dirB)) < 0 ? -1 : 1);//放回的值随夹角的增大而减小 }查看全部
-
Vector3 direction = Input.GetAxis("Horizontal") * transform.right + Input.GetAxis("Vertical") * transform.forward; transform.position = transform.position + walkSpeed * direction * Time.deltaTime;查看全部
-
prfabs作用 模板 1.重复利用 2.同时修改查看全部
举报
0/150
提交
取消