第一人称射击游戏

        生成和发射子弹代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class guncontral : MonoBehaviour
[
//枪口火焰生成位置
public Transform firepoint;
//枪口火焰物体
public GameObject fireper;
//子弹生成位置
public Transform bulletpoint;
//子弹物体
public GameObject bulletper;
//子弹个数
private int bulletCount=10;
/1开火间隔
private float cd = 0.2f;
//实际开火的时间 计时器
private float timer=0;
// Start is called before the first frame update
void Start()
(
)
// Update is called once per frame
void Update()
(
1/计算实际开火间隔
timer = timer + Time.deltaTime;
if (Input.GetMouseButton(0)&& bulletCount>0&&timer>cd) (
timer= 0;
//火焰生成
Instantiate(fireper, firepoint,position, firepoint.rotation);//子弹生成
Instantiate(bulletper, bulletpoint.position, bulletpoint.rotation); bulletCount--;
)

开枪音效代码

1/2 System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class quncontral :MonoBehaviour
//枪口火焰生成位置
public Transform firepoint;
//枪口火焰物体
public GameObject fireper,
/子弹生成位置
public Transform bulletpoint;
//子弹物体
public GameObject bulletper;
/1子弹个数
private int bulletCount=10;
// 开火间隔
private float cd = 0.2f;
//实际开火的时间 计时器
private float timer=0;
private AudioSource gunvoice;
public AudioClip clip;
// Start is called before the first frame update
void Start()
(
gunvoice =GetComponent<AudioSource>0);
)
// Update is called once per frame
void Update()
(
//计算实际开火间隔
timer = timer + Time.deltaTime;
if (Input.GetMouseButton(0)&& bulletCount>0&&timer>cd) (
timer = 0;
11火焰生成
Instantiate(fireper, firepoint,position, firepoint.rotation);
//子弹生成
Instantiate(bulletper, bulletpoint.postion,bulletpoint.rotation);
bulletCount--;
gunvoice.PlayOneShot(dlip);
)
)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值