您好,登錄后才能下訂單哦!
keep study very day!寫寫今天的學(xué)習(xí)收獲,今天學(xué)習(xí)到了平面坐標(biāo)跟世界坐標(biāo)的相互轉(zhuǎn)換。
using UnityEngine; using System.Collections; public class cameramove : MonoBehaviour { private Vector3 world; private float speed = 0;//物體移動(dòng)的速度 // Use this for initialization void Start() { world.x = -2; world.y = 0; world.z = 6; } // Update is called once per frame void Update() { Vector2 screenpos = Camera.main.WorldToScreenPoint(transform.position);//物體的世界坐標(biāo)轉(zhuǎn)化成屏幕坐標(biāo) Vector3 e = Input.mousePosition;//鼠標(biāo)的位置 //當(dāng)點(diǎn)擊鼠標(biāo)中鍵時(shí) if (Input.GetMouseButtonDown(2)) { //e.z=screenpos.z;//1.因?yàn)槭髽?biāo)的屏幕 Z 坐標(biāo)的默認(rèn)值是0,所以需要一個(gè)z坐標(biāo) //e.z=1;//將鼠標(biāo) //攝像機(jī)要垂直于x-z平面 //world=Camera.main.ScreenToWorldPoint(e); world = new Vector3(Input.mousePosition.x/Screen.width,Input.mousePosition.y/Screen.height,106f ); Vector3 world1= Camera.main.ViewportToWorldPoint(new Vector3(world.x, world.y, 106f)); //world.x = Camera.main.ScreenToWorldPoint(Input.mousePosition).x; //world.z = Camera.main.ScreenToWorldPoint(Input.mousePosition).y; //world.y = transform.position.y; print("new x:" + world.x); print("new y:" + world.y); print("new z:" + world.z); //創(chuàng)建物體 //GameObject goNew = GameObject.CreatePrimitive(PrimitiveType.Sphere); //goNew.transform.position = world1; transform.LookAt(world1); } } }
==================== 迂者 丁小未 CSDN博客專欄=================
MyBlog:http://blog.csdn.net/dingxiaowei2013 MyQQ:1213250243
Unity QQ群:858550 cocos2dx QQ群:280818155
====================== 相互學(xué)習(xí),共同進(jìn)步 ===================
轉(zhuǎn)載請(qǐng)注明出處:http://blog.csdn.net/dingxiaowei2013/article/details/14498293
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。