Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

C # how to use Unity particle system to make grenade explosion

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to use Unity particle system to make grenade explosion". In daily operation, I believe many people have doubts about how to use Unity particle system to make grenade explosion in c #. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use Unity particle system to make grenade explosion". Next, please follow the editor to study!

First, create the terrain

1. GameObject-> 3D Object- > Terrain to create a plane with terrain attributes

2. Terrain- > Last tool (Terrain Settings)-> Set Resolution- > SetHeightmap resolution, set the terrain to 500 terrain 500

3. Adjust the view

Hierarchy- > Camera, select the default camera

Hierarchy- > Camera- > Inspector- > Position- > Xerox 250, you can see a plane in the shape of a ladder in Game (adjust the XYZ value at any time later for the best effect)

4. Set the terrain height

SetHeight

Height- > 200

5. Set the terrain background

2. Application resource package

1. Download resources

Download the required resource package from the unity official website

"Third Person Controller-Basic Locomotion FREE.unitypackage"

"Environment Pack Free Forest Sample.unitypackage"

2. Import resources

Assets- > Import Package- > Custom Package- > Select the Package package

3, Project-> All Prefabs- > drag the ThirdPersonController_LITE preform that displays the portrait to the ground in the Scene window (the parameter can choose the default value), and drag the vThirdPersonCamera_LITE preform 3 times apart from the ThirdPersonController_LITE to the Scene window (the preform can track the movement of the human body, replacing the default Camera).

4. Select Hierarchy- > Untitled- > Main Camera, and uncheck the box on the left side of Main Camera under Inspector to invalidate Main Camera.

Third, making hand grenades

1. Import SceneShot.unitypackage

2. Put Grenade into the scene

3. Collisions.cs script (1) / / drag onto 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 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 () .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 script / / drag onto 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 () .AddForce (transform.forward * 20, ForceMode.Impulse); Collisions.GRENADE_AMMO--; print ("YOU NOW HAVE" + Collisions.GRENADE_AMMO + "GRENADES");}

5. GrenadeScript.cs script / / drag the script onto the grenade preform

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. Under the Assets directory of the current project file, create an Audio folder and copy the grenade explosion sound file Grenade.mp3 to the Audio folder.

Click the Project- > Assets- > Audio- > Grenade music file, and there is a run button at the bottom of the Inspector panel (the arrow on the right side of the Grenade bar at the bottom right) to listen to the sound effects.

Project- > Prefabs- > explosion- > Click Add Component-> Audio- > Audio Source in Inspector, and there is AudioClip under Audio Source in Inspector

Select the Grenade music component and click Hierarchy- > vThirdPersonCamera_LITE to view the component properties on the Inspector panel. Audio Listener can listen to the music effects in the scene while the game is running.

Run, press the left key of the keyboard, launch the grenade, the grenade disappears after landing, while producing the special effect of flame explosion, the sound effect of the grenade explosion can be detected.

7. Final effect

At this point, the study on "how to use Unity particle system to make grenade explosions" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report