日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Unity-多米诺骨牌

發布時間:2023/12/8 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Unity-多米诺骨牌 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
攝像機旋轉腳本
public class RotateAroundAndLookAt : MonoBehaviour {public GameObject rotateCenter; //旋轉中心對象public float rotateSpeed = 10.0f; //旋轉的速度// Update is called once per framevoid Update () {if(rotateCenter) //只有旋轉中心物體存在時才能進行物體的公轉{transform.RotateAround(rotateCenter.transform.position,//旋轉的中心點rotateCenter.transform.up,//旋轉軸 這里設置為Y軸朝上Time.deltaTime * rotateSpeed //旋轉的角度 表示每秒轉多少度);}} }
視角切換腳本
public class CameraSwitch : MonoBehaviour {public Camera mainCamera; //主攝像機public Camera orthCamera; //正交攝像機// Use this for initializationvoid Start () {mainCamera.enabled = true;//初始視角為主攝像機orthCamera.enabled = false;//初始時禁用正交攝像機 }// Update is called once per framevoid Update () {if(Input.GetKeyDown(KeyCode.S))//鍵盤S來切換視角{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>() //獲取游戲對象上的剛體組件 取消勾選Rigidbody使用重力選項.AddForce(new Vector3(0, -force, 0));//添加向下的的作用力即Y軸負方向} }
大球自轉腳本
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 {//當有物體與該物體即將發生碰撞時,調用OnCollisionEnter()函數void OnCollisionEnter(Collision collision) {if (collision.gameObject.tag.Equals("Domino")) //根據碰撞物體的標簽來判斷該物體是否為多米諾骨牌GetComponent<AudioSource>().Play(); //獲取多米諾骨牌撞擊音效的AudioSource組件并播放} }

最終效果

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。