国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

unity小技巧:實(shí)現(xiàn)拖拽三維物體效果

2023-07-24 14:49 作者:塵風(fēng)一枚  | 我要投稿

using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class MoveWorldBlockManager : MonoBehaviour

{


private IEnumerator OnMouseDown()

{

//將三維物體坐標(biāo)轉(zhuǎn)換成屏幕坐標(biāo)

Vector3 screenPosition = Camera.main.WorldToScreenPoint(transform.position);

//鼠標(biāo)屏幕坐標(biāo)

Vector3 currentScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPosition.z);

//將鼠標(biāo)屏幕坐標(biāo)轉(zhuǎn)換成三維坐標(biāo)

Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(currentScreenSpace);

//計(jì)算物體位置與鼠標(biāo)之間的距離

Vector3 offset = transform.position - mouseWorldPosition;

//提前定義好返回值

var cs = new WaitForFixedUpdate();

//當(dāng)按下鼠標(biāo)左鍵時(shí)

while (Input.GetMouseButton(0))

{

//更新鼠標(biāo)屏幕坐標(biāo)

currentScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPosition.z);

//將鼠標(biāo)屏幕坐標(biāo)轉(zhuǎn)換成三維坐標(biāo)

mouseWorldPosition = Camera.main.ScreenToWorldPoint(currentScreenSpace);

//移動(dòng)物體坐標(biāo)

Vector3 currentPosition = mouseWorldPosition + offset;

//將物體坐標(biāo)設(shè)置成移動(dòng)后的坐標(biāo)

transform.position = currentPosition;

//返回 (只有當(dāng)下一次fixedUpdate開始時(shí)再執(zhí)行后續(xù)代碼)

yield return cs;

}


}


}

unity小技巧:實(shí)現(xiàn)拖拽三維物體效果的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
渝北区| 临澧县| 海兴县| 富平县| 吴忠市| 周口市| 巴林左旗| 会理县| 舞钢市| 宁德市| 稻城县| 诸暨市| 阳城县| 琼结县| 梨树县| 吉水县| 镇原县| 盐城市| 百色市| 沙河市| 郯城县| 桐梓县| 西丰县| 通江县| 乌兰县| 故城县| 瑞金市| 长海县| 扶风县| 贵港市| 大田县| 佛学| 龙州县| 洪泽县| 高青县| 文安县| 榆树市| 云龙县| 潜山县| 吴堡县| 溧阳市|