您的位置:首页 > 移动开发 > Unity3D

Unity 音效播放

2020-06-21 04:20 1566 查看

目录

游戏开发所需音频文件

添加背景音乐

新建空对象

增加Audio Source组件

指定音频文件

循环播放、唤醒播放

添加音频播放脚本

给机器人加脚步声

设为3D空间混合

设置曲线

移除摄像机的监听器

在玩家上加一个监听器

游戏开发所需音频文件

背景音乐,走路,被打,击中敌人,完成任务等

添加背景音乐

新建空对象

增加Audio Source组件

指定音频文件

循环播放、唤醒播放

添加音频播放脚本

[code]using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AudioManager : MonoBehaviour
{
public static AudioManager instance { get; private set; }

private AudioSource audioS;

// Start is called before the first frame update
void Start()
{
instance = this;
audioS = GetComponent<AudioSource>();
}

// Update is called once per frame
void Update()
{

}

public void AudioPlay(AudioClip clip)
{
audioS.PlayOneShot(clip);
}
}

记得挂载这个脚本到空对象,不然报错

Object reference not set to an instance of an object Collect.OnTriggerEnter2D (UnityEngine.Collider2D other)

给机器人加脚步声

设为3D空间混合

设置曲线

移除摄像机的监听器

在玩家上加一个监听器

 

附完整教程:

Unity2d Rubys Adventure 课程设计报告

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: