欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

c#語言使用Unity粒子系統(tǒng)制作手雷爆炸

 更新時(shí)間:2022年04月25日 17:46:43   作者:極客范兒  
這篇文章主要為大家介紹了Unity的粒子系統(tǒng)由粒子發(fā)射器、粒子動(dòng)畫器、粒子渲染器組成,通過使用一或兩個(gè)紋理多次繪制,創(chuàng)造一個(gè)混沌的效果,通過復(fù)習(xí)粒子系統(tǒng)做一個(gè)手雷和實(shí)彈投擲現(xiàn)場

一、創(chuàng)建地形

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è)置地形背景

二、應(yīng)用資源包

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、最終效果

在這里插入圖片描述

以上就是c#語言使用Unity粒子系統(tǒng)制作手雷爆炸的詳細(xì)內(nèi)容,更多關(guān)于Unity粒子系統(tǒng)制作手雷爆炸的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論