标签:inpu span pre sep 矢量 答案 应用 屏幕 识别
if (Input.GetMouseButtonDown (0)) { //initial click to roll a dice initPos = Input.mousePosition; //return x component of dice from screen to view point initXpose = cam.ScreenToViewportPoint (Input.mousePosition).x; } //current position of mouse Vector3 currentPos = Input.mousePosition; //get all position along with mouse pointer movement Vector3 newPos = cam.ScreenToWorldPoint (newVector3(currentPos.x,currentPos.y,Mathf.Clamp(currentPos.y/10,10,50))); //translate from screen to world coordinates newPos = cam.ScreenToWorldPoint (currentPos); if (Input.GetMouseButtonUp (0)) { initPos = cam.ScreenToWorldPoint (initPos); //Method use to roll the dice RollTheDice(newPos); //use identify face value on dice StartCoroutine(GetDiceCount ()); } //Method Roll the Dice void RollTheDice(Vector3 lastPos) { diceObject.rigidbody.AddTorque(Vector3.Cross(lastPos, initPos) * 1000, orceMode.Impulse); lastPos.y += 12; diceObject.rigidbody.AddForce (((lastPos - initPos).normalized) * (Vector3.Distance (lastPos, initPos)) * 25 * duceObject.rigidbody.mass); }
//Coroutine to get dice count void GetDiceCount() { if (Vector3.Dot (transform.forward, Vector3.up) > 1) diceCount = 5; if (Vector3.Dot (-transform.forward, Vector3.up) > 1) diceCount = 2; if (Vector3.Dot (transform.up, Vector3.up) > 1) diceCount = 3; if (Vector3.Dot (-transform.up, Vector3.up) >1) diceCount = 4; if (Vector3.Dot (transform.right, Vector3.up) >1) diceCount = 6; if (Vector3.Dot (-transform.right, Vector3.up) >1) diceCount = 1; Debug.Log ("diceCount :" + diceCount); }
原文链接:http://www.theappguruz.com/blog/roll-a-dice-unity-3d
标签:inpu span pre sep 矢量 答案 应用 屏幕 识别
原文地址:http://www.cnblogs.com/unity3d-Yang/p/6924938.html