Unity-多米诺骨牌
生活随笔
收集整理的這篇文章主要介紹了
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)題。
- 上一篇: Unity DOTS系统概览
- 下一篇: 医药股分析