日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Unity-多米诺骨牌

發(fā)布時(shí)間:2023/12/8 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Unity-多米诺骨牌 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
攝像機(jī)旋轉(zhuǎn)腳本
public class RotateAroundAndLookAt : MonoBehaviour {public GameObject rotateCenter; //旋轉(zhuǎn)中心對(duì)象public float rotateSpeed = 10.0f; //旋轉(zhuǎn)的速度// Update is called once per framevoid Update () {if(rotateCenter) //只有旋轉(zhuǎn)中心物體存在時(shí)才能進(jìn)行物體的公轉(zhuǎn){transform.RotateAround(rotateCenter.transform.position,//旋轉(zhuǎn)的中心點(diǎn)rotateCenter.transform.up,//旋轉(zhuǎn)軸 這里設(shè)置為Y軸朝上Time.deltaTime * rotateSpeed //旋轉(zhuǎn)的角度 表示每秒轉(zhuǎn)多少度);}} }
視角切換腳本
public class CameraSwitch : MonoBehaviour {public Camera mainCamera; //主攝像機(jī)public Camera orthCamera; //正交攝像機(jī)// Use this for initializationvoid Start () {mainCamera.enabled = true;//初始視角為主攝像機(jī)orthCamera.enabled = false;//初始時(shí)禁用正交攝像機(jī) }// Update is called once per framevoid Update () {if(Input.GetKeyDown(KeyCode.S))//鍵盤S來(lái)切換視角{mainCamera.enabled = !mainCamera.enabled;orthCamera.enabled = !orthCamera.enabled;} } }
給大球添加作用力腳本
public class ObjectAddForce : MonoBehaviour {public int force;//作用力大小 // Update is called once per framevoid Update () {gameObject.GetComponent<Rigidbody>() //獲取游戲?qū)ο笊系膭傮w組件 取消勾選Rigidbody使用重力選項(xiàng).AddForce(new Vector3(0, -force, 0));//添加向下的的作用力即Y軸負(fù)方向} }
大球自轉(zhuǎn)腳本
public class SelfRotate : MonoBehaviour {public float rotateSpeed = 40.0f; // Update is called once per framevoid Update () {transform.Rotate(Vector3.up, Time.deltaTime * rotateSpeed);} }
音效播放腳本
public class DominoCollide : MonoBehaviour {//當(dāng)有物體與該物體即將發(fā)生碰撞時(shí),調(diào)用OnCollisionEnter()函數(shù)void OnCollisionEnter(Collision collision) {if (collision.gameObject.tag.Equals("Domino")) //根據(jù)碰撞物體的標(biāo)簽來(lái)判斷該物體是否為多米諾骨牌GetComponent<AudioSource>().Play(); //獲取多米諾骨牌撞擊音效的AudioSource組件并播放} }

最終效果

總結(jié)

以上是生活随笔為你收集整理的Unity-多米诺骨牌的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。