游戏场景——主玩家——可击毁箱子
添加特效
CubeObj的代码如下
?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CubeObj : MonoBehaviour
{
//关联的奖励物品
public GameObject[] rewardObjects;
//关联的特效
public GameObject deadEff;
private void OnTriggerEnter(Collider other)
{
BulletObj bullet = other.GetComponent<BulletObj>();
TankBaseObj tank = bullet.fatherObj;
if(tank is PlayerObj)
{
int randomIndex = Random.Range(0, rewardObjects.Length);
Instantiate(rewardObjects[randomIndex], transform.position, transform.rotation);
//创建一个奖励特效
GameObject eff = Instantiate(deadEff, transform.position, transform.rotation);
//控制特效的音效
AudioSource audioSource = eff.GetComponent<AudioSource>();
audioSource.volume = GameDataMgr.Instance.musicData.soundValue;
audioSource.mute = !GameDataMgr.Instance.musicData.isOpenSound;
Destroy(gameObject);
}
}
}