回復アイテムの設定を変更する

ShellItemスクリプトの変更
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShellItem : MonoBehaviour
{
public AudioClip getSound;
public GameObject effectPrefab;
private ShotShell ss;
private int reward = 5;
private void OnTriggerEnter(Collider other)
{
// ★変更
// タグの名称を「Player1」に変更する
if (other.gameObject.tag == "Player1")
{
// ★変更
// 「ShotShell」の末尾に「1」を付ける。
ss = GameObject.Find("ShotShell1").GetComponent<ShotShell>();
ss.AddShell(reward);
Destroy(gameObject);
AudioSource.PlayClipAtPoint(getSound, Camera.main.transform.position);
GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
Destroy(effect, 0.5f);
} // ★追加 タグの名称は「Player2」
else if (other.gameObject.tag == "Player2")
{
// 「ShotShell」の末尾に「2」を付ける。
ss = GameObject.Find("ShotShell2").GetComponent<ShotShell>();
ss.AddShell(reward);
Destroy(gameObject);
AudioSource.PlayClipAtPoint(getSound, Camera.main.transform.position);
GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
Destroy(effect, 0.5f);
}
}
}





ShellItemスクリプトの変更
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShellItem : MonoBehaviour
{
public AudioClip getSound;
public GameObject effectPrefab;
private ShotShell ss;
private int reward = 5;
private void OnTriggerEnter(Collider other)
{
// ★変更
// タグの名称を「Player1」に変更する
if (other.gameObject.tag == "Player1")
{
// ★変更
// 「ShotShell」の末尾に「1」を付ける。
ss = GameObject.Find("ShotShell1").GetComponent<ShotShell>();
ss.AddShell(reward);
Destroy(gameObject);
AudioSource.PlayClipAtPoint(getSound, Camera.main.transform.position);
GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
Destroy(effect, 0.5f);
} // ★追加 タグの名称は「Player2」
else if (other.gameObject.tag == "Player2")
{
// 「ShotShell」の末尾に「2」を付ける。
ss = GameObject.Find("ShotShell2").GetComponent<ShotShell>();
ss.AddShell(reward);
Destroy(gameObject);
AudioSource.PlayClipAtPoint(getSound, Camera.main.transform.position);
GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
Destroy(effect, 0.5f);
}
}
}




回復アイテムの設定を変更する