-
until3d基本流程查看全部
-
如何更新邏輯查看全部
-
如何通過腳本驅(qū)動游戲查看全部
-
C#和unityscript component查看全部
-
我就截個圖查看全部
-
創(chuàng)建了一些地形,比較有用查看全部
-
11122查看全部
-
游戲開發(fā)查看全部
-
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> (); }查看全部
-
//(系統(tǒng)函數(shù))沒daltTime調(diào)用一次(通常處理物理運算) void FixedUpdate () { serFaceingDirection (); //使物體朝著鼠標(biāo)旋轉(zhuǎn) UpdateRotation (); } //設(shè)置旋轉(zhuǎn)的方向(及鼠標(biāo)在物體運動平面的坐標(biāo)(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,并設(shè)置dist的值(及焦點與射線源點的距離) Vector3 vect=ray.GetPoint(dist);//放回沿射線距離為dist的點 return vect; }查看全部
-
//更新物體的旋轉(zhuǎn)角度(及剛體的角速度) 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); //設(shè)置剛體的角速度 GetComponent<Rigidbody> ().angularVelocity = (Vector3.up * rotationAngle * turningSmoothing); } }查看全部
-
將老師間的人物跟著鼠標(biāo)旋轉(zhuǎn)的代碼整理了下: // 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);//得到鼠標(biāo)前后兩次位置在平面上的轉(zhuǎn)動的角度 // 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.重復(fù)利用 2.同時修改查看全部
舉報
0/150
提交
取消