赞
踩
学习资源:B站 M_Studio《Unity教程2D入门》18
Unity Assets:Sunnyland
Audio Listener:耳朵,用来听声音的——一般放在main camera下
Audio Source:喇叭,音源,放在哪就从哪出声音
Audio Clips:声音片段
main camera默认有Audio Listener组件。
给player添加Audio Source。
小技巧:
注意到这边有条蓝色的边边,说明不是预制体中改变而是临时改变。
希望每个场景中有player都有这个声音的话,点击右上角
Overrides->Apply All 就可以把修改的效果自动添加到预制体中。
选中BGM,属性面板中可以试听。
选择Play on wake游戏一开始就播放,Loop循环播放,Volume调节音量。
为frog添加音效。因为不是bgm,这两个就不需要勾选。
要在不同敌人死亡时都播放该音频,因此不需要在每个敌人类下写,还记得上节课的内容吗,直接在enemy类里写。
当前脚本如下:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Enemy : MonoBehaviour { protected Animator anim; protected AudioSource deathAudio; protected virtual void Start() { anim = GetComponent<Animator>(); deathAudio = GetComponent<AudioSource>(); } public void setDeath() { anim.SetTrigger("Death"); deathAudio.Play(); } public void DestroySelf() { Destroy(gameObject); } }
问题:那getcomponent的时候,如何区分jump和bgm的audio resource呢?
设置成public,然后拖入就好。
public AudioSource jumpAudio;
添加受伤、吃金币等音效,同理。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。