最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Unity實(shí)現(xiàn)鼠標(biāo)點(diǎn)2D轉(zhuǎn)3D進(jìn)行旋轉(zhuǎn)

 更新時(shí)間:2020年04月17日 11:53:20   作者:木小星  
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)鼠標(biāo)點(diǎn)2D轉(zhuǎn)3D進(jìn)行旋轉(zhuǎn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Unity實(shí)現(xiàn)鼠標(biāo)點(diǎn)2D轉(zhuǎn)3D進(jìn)行旋轉(zhuǎn)的具體代碼,供大家參考,具體內(nèi)容如下

代碼如下:

using UnityEngine;

public class GunFollowMouse : MonoBehaviour {
  public RectTransform UGUICanvas;
  public Camera mainCamera;
  //攝像機(jī)旋轉(zhuǎn)的緩動(dòng)速率
  private float rotateSpeed = 5;
  void Start () {
 
 }
 
 void Update () {
    //定義一個(gè)世界坐標(biāo)的鼠標(biāo)點(diǎn)
    Vector3 mousePos;
    //獲取當(dāng)前canvas下鼠標(biāo)的二維坐標(biāo)點(diǎn) 轉(zhuǎn)化為三維 out出來(lái)
    RectTransformUtility.ScreenPointToWorldPointInRectangle(UGUICanvas,
      new Vector2(Input.mousePosition.x, Input.mousePosition.y),
      mainCamera, out mousePos
      );
    //炮臺(tái)的旋轉(zhuǎn)角度
    float angle;
    //向量dirMouse為鼠標(biāo)的向量減去槍的起始向量得到槍到鼠標(biāo)位置的方向向量
    Vector3 dirMouse = mousePos - transform.position;
    angle = Vector3.Angle(dirMouse, Vector3.up);//直接得到兩個(gè)向量之間的夾角,這個(gè)角度是沒(méi)有正負(fù)的
    if (mousePos.x > transform.position.x)
    {
      angle = - angle;
    }
    transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.Euler(0, 0, angle)
      , Time.deltaTime * rotateSpeed);
 }
}

旋轉(zhuǎn)效果如下圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

石狮市| 河津市| 桐梓县| 夹江县| 银川市| 耒阳市| 木里| 湾仔区| 洛隆县| 梨树县| 武邑县| 农安县| 桑日县| 乌兰察布市| 固原市| 长岭县| 汉源县| 潮安县| 德阳市| 敖汉旗| 南涧| 昭平县| 鹰潭市| 清远市| 肇庆市| 耿马| 东乌珠穆沁旗| 新疆| 东光县| 铁岭县| 赤壁市| 新田县| 沙湾县| 扎兰屯市| 区。| 鞍山市| 昭觉县| 丰台区| 平潭县| 安国市| 南郑县|