您好,登錄后才能下訂單哦!
這篇文章主要介紹“c#怎么使用Unity粒子系統制作手雷爆炸”,在日常操作中,相信很多人在c#怎么使用Unity粒子系統制作手雷爆炸問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”c#怎么使用Unity粒子系統制作手雷爆炸”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
1、GameObject ->3D Object-> Terrain,創建帶有地形屬性的平面
2、Terrain-〉最后一個工具(Terrain Settings)->Set Resolution-〉SetHeightmap resolution ,把地形設置為500*500
3、調整視圖
Hierarchy->Camera,選擇默認的攝像機
Hierarchy->Camera->Inspector->Position->X=250,Y=100,Z=-250, Game中能看到一個梯形狀的平面(以后隨時調整XYZ值得到最佳效果)
4、設置地形高度
SetHeight
Height->200
5、設置地形背景
1、下載資源
從unity官網中下載好所需要的資源包
“Third Person Controller - Basic Locomotion FREE.unitypackage”
“Environment Pack Free Forest Sample.unitypackage”
2、導入資源
Assets->Import Package->Custom Package->依次選中Package包
3、Project ->All Prefabs->將顯示人像的ThirdPersonController_LITE預制件拖拉到Scene窗口中的地面上(參數可以選用默認值),同時將與ThirdPersonController_LITE相隔3個的vThirdPersonCamera_LITE預制件拖拉到Scene窗口中(該預制件能跟蹤人體的運動,替代默認的Camera)。
4、選中Hierarchy-〉Untitled->Main Camera,在Inspector下的Main Camera左邊的小框中的勾選去掉,讓Main Camera失效。
1、導入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預制體上
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、在當前工程文件的Assets目錄下,建一個Audio文件夾,將手榴彈爆炸音效文件Grenade.mp3,拷貝到Audio文件夾中
點擊Project->Assets->Audio->Grenade音樂文件,在Inspector面板最下方有一個運行按鈕(右下方的Grenade欄右邊的箭頭),可以傾聽音效
Project-〉Prefabs-〉explosion- >在Inspector中點擊Add Component ->Audio->Audio Source,在Inspector中的Audio Source下有AudioClip,
選Grenade音樂組件單擊Hierarchy-〉vThirdPersonCamera_LITE,查看Inspector面板上的組件屬性,Audio Listener起到在游戲運行時偵聽場景中的音樂效果
運行,按鍵盤的左健,發射手榴彈,手榴彈落地后消失,在產生火焰爆炸特效的同時,可以偵聽到手榴彈爆炸的聲音特效
7、最終效果
到此,關于“c#怎么使用Unity粒子系統制作手雷爆炸”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。