用AudioSource播放声音


不需要在玩家身上添加AudioSource组件

资源管理类


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//资源管理类
public class GameRes  {
	//标签
	public const string player = "Player";
	public const string dog = "Dog";
	public const string nurse = "Nurse";
	//名称
	public const string canvas = "Canvas";
	//声音路径
	public const string ak_firePath = "Sounds/AK_fire";
	public const string landDefaultPath = "Sounds/landDefault";
	public const string ak_readyPath = "Sounds/AK_ready";
	public const string shellFall1Path = "Sounds/ShellFall1";
	public const string dgDiePath = "Sounds/DgDie";
	public const string zombieattackPath = "Sounds/zombieattack";
	public const string zombieDiePath = "Sounds/zombieDie";
	public const string PropsPath = "Sounds/Se_UI_Props";
	public const string NailPath = "Sounds/Se_UI_Nail";
	public const string alarmPath = "Sounds/alarm_triggered";
	//预设体路径
	public const string holePath = "Prefabs/hole";
	public const string player1Path = "Prefabs/Player1";
	public const string player2Path = "Prefabs/Player2";
	public const string nursePath = "Prefabs/Nurse";
	public const string dogPath = "Prefabs/Dog";
    //特效路径
    public const string effectPath = "Effects/RIFLE1";
    public const string explosoinPath = "Effects/WFX_Explosion";
  
	//枚举
	public enum PlayerState
    {
		Idle,
		Fire,
		Reload,//换子弹
		Melee //换枪
	}
	public enum EnemyState
	{
		Idle,
		Run,
		Attack,
		Death
	}
}

玩家类


public class Player : MonoBehaviour
{
   AudioSource audios;//1.资源组件
   AudioClip fireclip;//2.开枪声音
    void Start()
 {
 audios = GetComponent<AudioSource>();//3获取组件
  fireclip = Resources.Load<AudioClip>(GameRes.ak_firePath);//4.获取声音
 }
void Start()
{
 Fire();
}
 
 void Fire()
{
   AudioSource.PlayClipAtPoint(fireclip, pos.position);//5.播放声音
}
  
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值