4月4日
今天心情有点差,突然不想开学了
试着给游戏添加音效,撞击时给他来个“欧拉!”,死亡时给他整个“木大!”,背景音乐加白金之星处刑曲、
创建一个空物体承载bgm,导入血条参数,血量越少,bgm播放速度越快,当血量为0,音量逐渐减少为0
public Image life;
public AudioSource bgm;
// Start is called before the first frame update
void Start()
{
bgm = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
if (life.fillAmount == 0)
bgm.volume -= Time.deltaTime*0.5f;
bgm.pitch = 1+0.2f*(1-life.fillAmount);
}
}
然后是在撞击小球的时候添加音效
if (collision.gameObject.tag == "Enemy")
{
Destroy(collision.gameObject);
float vx = collision.gameObject.transform.position.x - transform.position.x;
rb.velocity = (Vector2.up * 3 + new Vector2(vx, 0)) * speedForc