c#语言使用Unity粒子系统制作 * *
作者:极客范儿 发布时间:2021-10-11 11:13:46
一、创建地形
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、最终效果
来源:https://blog.csdn.net/Prototype___/article/details/124372413
猜你喜欢
- 最近项目进行适配的时候发现部分(如华为手机)存在底部虚拟按键的手机会因为虚拟按键的存在导致挡住部分界面,因为需要全屏显示,故调用虚拟按键隐藏
- 预加载bean在springBoot启动过程中就完成创建加载在AbstractApplicationContext的refresh方法中//
- 前言在unity的ugui中Text控件,有时我们会有各种各样的需求,比如类似html中css的text-overflow属性,希望一段文字
- 首先在枚举类中 定义state 和定义的抽象方法。public enum JavaPlatformState { // 定义st
- 本文实例讲述了C#使用XML序列化操作菜单的方法。分享给大家供大家参考。具体分析如下:之前的一篇文章《C#递归读取XML菜单数据的方法》没使
- 使用 DateFormat 格式化日期、时间DateFormat 也是一个抽象类,它也提供了如下几个类方法用于获取 DateFormat 对
- 1. 概述官方JavaDocsApi: javax.swing.JList JList,列表框。JList 以列表的形式展示多个选项,允许用
- 上篇文章给大家介绍了,喜欢的朋友点击查看下。SpringBoot 开发提速神器 Lombok+MybatisPlus+SwaggerUILo
- 一、JDK中常见的异常情况1、常见异常总结图2、java中异常分类Throwable类有两个直接子类:(1)Exception:出现的问题是
- 静态代理: 由我们开发者自己手动创建或者在程序运行前就已经存在的代理类,静态代理通常只代理一个类, * 是代理一个接口下的多个实现类。动态
- 本文实例讲述了C#计算字符串哈希值(MD5、SHA)的方法。分享给大家供大家参考。具体如下:一、关于本文本文中是一个类库,包括下面几个函数:
- 本文主要给大家介绍了关于Java8中Optional类型和Kotlin中可空类型使用的相关内容,分享出来供大家参考学习,下面话不多说了,来一
- 一、前言介绍:1.1 课题背景 互联网发展至今,无论是其理论还是技术都已经成熟,而且
- 题目描述在进行网络编程时,有时需要对局域网的所有主机进行遍历,为此需要获得内网的所以IP地址题目实现:获得内网的所有IP地址的小应用。解题思
- Spring Boot 自动装配最重要的注解@SpringBootApplication@Target(ElementType.TYPE)@
- 实现 bean 初始化、摧毁方法的配置与处理spring支持我们自定义 bean 的初始化方法和摧毁方法。配置方式可以通过 xml 的 in
- 本章讲述:FileStream类的基本功能,以及简单示例;1、引用命名空间:using System.IO;2、注意:使用IO操作文件时,要
- 1.什么是继承?(1)用来提高代码的复用性(2)将相同的功能模块封装到方法中需要使用时调用方法达到代码复用的目的(3)通过继承将多个类中的相
- 一. 线性表中的顺序表线性表(linear list)是n个具有相同特性的数据元素的有限序列。 线性表是一种在实际中广泛使用的数据结构,常见
- 目录前言步入正题类的加载过程:1.加载2.验证3.准备4.解析5.初始化类加载器源码总结前言学生时代应抱着问题去学习一门语言,例如:在学习j