您好,登錄后才能下訂單哦!
這篇文章主要介紹“c#怎么使用Unity粒子系統(tǒng)制作手雷爆炸”,在日常操作中,相信很多人在c#怎么使用Unity粒子系統(tǒng)制作手雷爆炸問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對(duì)大家解答”c#怎么使用Unity粒子系統(tǒng)制作手雷爆炸”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
1、GameObject ->3D Object-> Terrain,創(chuàng)建帶有地形屬性的平面
2、Terrain-〉最后一個(gè)工具(Terrain Settings)->Set Resolution-〉SetHeightmap resolution ,把地形設(shè)置為500*500
3、調(diào)整視圖
Hierarchy->Camera,選擇默認(rèn)的攝像機(jī)
Hierarchy->Camera->Inspector->Position->X=250,Y=100,Z=-250, Game中能看到一個(gè)梯形狀的平面(以后隨時(shí)調(diào)整XYZ值得到最佳效果)
4、設(shè)置地形高度
SetHeight
Height->200
5、設(shè)置地形背景
1、下載資源
從unity官網(wǎng)中下載好所需要的資源包
“Third Person Controller - Basic Locomotion FREE.unitypackage”
“Environment Pack Free Forest Sample.unitypackage”
2、導(dǎo)入資源
Assets->Import Package->Custom Package->依次選中Package包
3、Project ->All Prefabs->將顯示人像的ThirdPersonController_LITE預(yù)制件拖拉到Scene窗口中的地面上(參數(shù)可以選用默認(rèn)值),同時(shí)將與ThirdPersonController_LITE相隔3個(gè)的vThirdPersonCamera_LITE預(yù)制件拖拉到Scene窗口中(該預(yù)制件能跟蹤人體的運(yùn)動(dòng),替代默認(rèn)的Camera)。
4、選中Hierarchy-〉Untitled->Main Camera,在Inspector下的Main Camera左邊的小框中的勾選去掉,讓Main Camera失效。
1、導(dǎo)入SceneShot.unitypackage
2、將Grenade置入場景中
3、Collisions.cs腳本程序(1) //拖拽到ThirdPersonController_LITE上
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Collisions : MonoBehaviour { public static int GRENADE_AMMO = 0; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { RaycastHit hit; //check if we are collidering float rayCastLength = 5; Vector3 offset = new Vector3(0,0.5f,0); if (Physics.Raycast(transform.position+offset, transform.forward,out hit ,rayCastLength )) { //...with a door if (hit.collider.gameObject.tag == "Door") { //open the door hit.collider.gameObject.GetComponent<Animation>().Play("Door-open"); } } Debug.DrawRay(transform.position + offset, transform.forward, Color.red); } void OnTriggerEnter(Collider hit) { if (hit.gameObject.tag == "CrateGrenades") { Debug.Log("hit"); //destory the ammo box Destroy(hit.gameObject); //add ammo to inventory GRENADE_AMMO += 200; print("YOU NOW HAVE " + GRENADE_AMMO + " GRENADES"); } } }
4、Shooting.cs腳本程序 //拖拽到ThirdPersonController_LITE上
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Shooting : MonoBehaviour { // Start is called before the first frame update float speed = 3; Vector3 offset = new Vector3(0, 1.0f, 0f); [Tooltip("gp")] public GameObject GrenadePrefab; void Start() { } // Update is called once per frame void Update() { Screen.lockCursor = true; //find out if a fire button is pressed if (Input.GetMouseButtonDown(0)) { Debug.Log("shoot"); if (Collisions.GRENADE_AMMO > 0) { //create the prefab GameObject grenade = Instantiate(GrenadePrefab, this.transform.localPosition+ offset+ transform.forward, Quaternion.identity); //add force to the prefab grenade.GetComponent<Rigidbody>().AddForce(transform.forward * 20, ForceMode.Impulse); Collisions.GRENADE_AMMO--; print("YOU NOW HAVE " + Collisions.GRENADE_AMMO + " GRENADES"); } } } }
5、GrenadeScript.cs腳本程序 //將腳本拖拽到grenade預(yù)制體上
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class GrenadeScript:MonoBehaviour { private float creationTime; public GameObject explosionPrefab; int lifetime = 3; // Start is called before the first frame update void Start() { } void Awake() { Debug.Log("count"); creationTime = Time.time; } // Update is called once per frame void Update() { if (Time.time > (creationTime + lifetime)) { //Destroy(this.gameObject); Instantiate(explosionPrefab, transform.position, Quaternion.identity); } } }
6、在當(dāng)前工程文件的Assets目錄下,建一個(gè)Audio文件夾,將手榴彈爆炸音效文件Grenade.mp3,拷貝到Audio文件夾中
點(diǎn)擊Project->Assets->Audio->Grenade音樂文件,在Inspector面板最下方有一個(gè)運(yùn)行按鈕(右下方的Grenade欄右邊的箭頭),可以傾聽音效
Project-〉Prefabs-〉explosion- >在Inspector中點(diǎn)擊Add Component ->Audio->Audio Source,在Inspector中的Audio Source下有AudioClip,
選Grenade音樂組件單擊Hierarchy-〉vThirdPersonCamera_LITE,查看Inspector面板上的組件屬性,Audio Listener起到在游戲運(yùn)行時(shí)偵聽場景中的音樂效果
運(yùn)行,按鍵盤的左健,發(fā)射手榴彈,手榴彈落地后消失,在產(chǎn)生火焰爆炸特效的同時(shí),可以偵聽到手榴彈爆炸的聲音特效
7、最終效果
到此,關(guān)于“c#怎么使用Unity粒子系統(tǒng)制作手雷爆炸”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。