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

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

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

一、創(chuàng)建地形

1、GameObject ->3D Object-> Terrain,創(chuàng)建帶有地形屬性的平面

2、Terrain-〉最后一個工具(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中能看到一個梯形狀的平面(以后隨時調(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)值),同時將與ThirdPersonController_LITE相隔3個的vThirdPersonCamera_LITE預(yù)制件拖拉到Scene窗口中(該預(yù)制件能跟蹤人體的運(yùn)動,替代默認(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目錄下,建一個Audio文件夾,將手榴彈爆炸音效文件Grenade.mp3,拷貝到Audio文件夾中

點擊Project->Assets->Audio->Grenade音樂文件,在Inspector面板最下方有一個運(yùn)行按鈕(右下方的Grenade欄右邊的箭頭),可以傾聽音效

Project-〉Prefabs-〉explosion- >在Inspector中點擊Add Component ->Audio->Audio Source,在Inspector中的Audio Source下有AudioClip,

選Grenade音樂組件單擊Hierarchy-〉vThirdPersonCamera_LITE,查看Inspector面板上的組件屬性,Audio Listener起到在游戲運(yùn)行時偵聽場景中的音樂效果

運(yùn)行,按鍵盤的左健,發(fā)射手榴彈,手榴彈落地后消失,在產(chǎn)生火焰爆炸特效的同時,可以偵聽到手榴彈爆炸的聲音特效

在這里插入圖片描述

在這里插入圖片描述

7、最終效果

在這里插入圖片描述

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

相關(guān)文章

  • c# 實現(xiàn)輪詢算法實例代碼

    c# 實現(xiàn)輪詢算法實例代碼

    這篇文章主要介紹了c# 實現(xiàn)輪詢算法實例代碼的相關(guān)資料,這里附有實例代碼,具有一定的參考價值,需要的朋友可以參考下
    2016-12-12
  • C# FileStream簡單介紹和使用

    C# FileStream簡單介紹和使用

    這篇文章主要為大家詳細(xì)介紹了C# FileStream基本功能和使用,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • C#連接Informix數(shù)據(jù)庫的問題

    C#連接Informix數(shù)據(jù)庫的問題

    這篇文章主要介紹了C#連接Informix數(shù)據(jù)庫的問題,本文給大家介紹的非常詳細(xì),對大家的工作或?qū)W習(xí)具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-03-03
  • DevExpress實現(xiàn)禁用TreeListNode CheckBox的方法

    DevExpress實現(xiàn)禁用TreeListNode CheckBox的方法

    這篇文章主要介紹了DevExpress實現(xiàn)禁用TreeListNode CheckBox的方法,在項目開發(fā)中有應(yīng)用價值,需要的朋友可以參考下
    2014-08-08
  • C#自定義處理xml數(shù)據(jù)類實例

    C#自定義處理xml數(shù)據(jù)類實例

    這篇文章主要介紹了C#自定義處理xml數(shù)據(jù)類,涉及C#針對XML的打開、讀寫等常用操作,并將其封裝進(jìn)一個類中以便于調(diào)用,非常具有實用價值,需要的朋友可以參考下
    2015-03-03
  • C#實現(xiàn)ComboBox自動匹配字符

    C#實現(xiàn)ComboBox自動匹配字符

    本文介紹C#如何實現(xiàn)ComboBox自動匹配字符1.采用CustomSource當(dāng)做提示集合2. 直接使用下拉列表中的項作為匹配的集合,需要了解的朋友可以參考下
    2012-12-12
  • unity實現(xiàn)屏幕上寫字效果

    unity實現(xiàn)屏幕上寫字效果

    這篇文章主要為大家詳細(xì)介紹了unity實現(xiàn)屏幕上寫字效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • C# winfroms使用socket客戶端服務(wù)端的示例代碼

    C# winfroms使用socket客戶端服務(wù)端的示例代碼

    這篇文章主要為大家詳細(xì)介紹了C# winfroms使用socket客戶端服務(wù)端的相關(guān)知識,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-02-02
  • C# SDK實現(xiàn)百度云OCR的文字識別功能

    C# SDK實現(xiàn)百度云OCR的文字識別功能

    這篇文章主要為大家詳細(xì)介紹了C# SDK實現(xiàn)百度云OCR的文字識別功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • C#使用正則表達(dá)式隱藏手機(jī)號中間四位為*

    C#使用正則表達(dá)式隱藏手機(jī)號中間四位為*

    這篇文章主要介紹了C#使用正則表達(dá)式隱藏手機(jī)號中間四位為*的相關(guān)資料,需要的朋友可以參考下
    2017-06-06

最新評論