回復アイテムの設定を変更する
![0f51b9df dbda 4bc9 af58 9d093cde315e](https://codegenius.org/uploads/slide/image/2272/0f51b9df-dbda-4bc9-af58-9d093cde315e.jpeg)
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);
}
}
}
![D4a520e3 9d44 46c5 b100 c8fe6cafd30c](https://codegenius.org/uploads/slide/image/2273/d4a520e3-9d44-46c5-b100-c8fe6cafd30c.jpeg)
![6456de04 e1c2 4d4a abcf bfe95ecd98ce](https://codegenius.org/uploads/slide/image/2274/6456de04-e1c2-4d4a-abcf-bfe95ecd98ce.jpeg)
![937af77b 95b0 4d88 80dc 8768b3c4489d](https://codegenius.org/uploads/slide/image/2275/937af77b-95b0-4d88-80dc-8768b3c4489d.jpeg)
![D78db7c0 63fb 4244 af7c f2ce7fea3a5e](https://codegenius.org/uploads/slide/image/2276/d78db7c0-63fb-4244-af7c-f2ce7fea3a5e.jpeg)
![0f51b9df dbda 4bc9 af58 9d093cde315e](https://codegenius.org/uploads/slide/image/2272/0f51b9df-dbda-4bc9-af58-9d093cde315e.jpeg)
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);
}
}
}
![D4a520e3 9d44 46c5 b100 c8fe6cafd30c](https://codegenius.org/uploads/slide/image/2273/d4a520e3-9d44-46c5-b100-c8fe6cafd30c.jpeg)
![6456de04 e1c2 4d4a abcf bfe95ecd98ce](https://codegenius.org/uploads/slide/image/2274/6456de04-e1c2-4d4a-abcf-bfe95ecd98ce.jpeg)
![937af77b 95b0 4d88 80dc 8768b3c4489d](https://codegenius.org/uploads/slide/image/2275/937af77b-95b0-4d88-80dc-8768b3c4489d.jpeg)
![D78db7c0 63fb 4244 af7c f2ce7fea3a5e](https://codegenius.org/uploads/slide/image/2276/d78db7c0-63fb-4244-af7c-f2ce7fea3a5e.jpeg)
回復アイテムの設定を変更する