一、前言
本篇博客记录的内容为上篇的延续,将介绍完成的射击反馈震屏、子弹散射等工作内容。实现了子弹击中物体产生弹孔的功能。
二、枪械射击弹孔及音效
在之前导入的特效包中找到Bullet_GoldFire_Small_Impact,然后拖拽到场景中去。

在Weapon文件夹下创建一个Bullet脚本,在其中完成设计弹孔的相关逻辑的编写。由于rigidbody会产生资源的消耗,所用用transform来移动就可以。
using System;
using Unity.Mathematics;
using UnityEngine;
using Random = UnityEngine.Random;
namespace Scripts.Weapon
{
public class Bullet : MonoBehaviour
{
public float BulletSpeed;//子弹速度
public GameObject ImpactPrefab;
public ImpactAudioData ImpactAudioData;
private Transform bulletTransform;
private Vector3 prevPosition;
private void Start()
{
bulletTransform = transform;
prevPosition = bulletTransform.position;//初始化
}
private void Update()
{
prevPosition = bulletTransform.position;
bulletTransform.</

最低0.47元/天 解锁文章
159

被折叠的 条评论
为什么被折叠?



