マネーポイント獲得システム
![59e54774 11a7 4f13 945a 5deb2fe6c67b](https://codegenius.org/uploads/slide/image/3894/59e54774-11a7-4f13-945a-5deb2fe6c67b.jpeg)
![5d57c349 9078 48b3 9220 46117cd4de74](https://codegenius.org/uploads/slide/image/3895/5d57c349-9078-48b3-9220-46117cd4de74.jpeg)
![F60cbc64 15ed 46ac 8e7c be7f1f42f2f8](https://codegenius.org/uploads/slide/image/3896/f60cbc64-15ed-46ac-8e7c-be7f1f42f2f8.jpeg)
![378c5d61 4d17 462f 8f9f 687f503dadc5](https://codegenius.org/uploads/slide/image/3897/378c5d61-4d17-462f-8f9f-687f503dadc5.jpeg)
獲得したマネーポイントの表示
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GPManager : MonoBehaviour
{
private Text gpLabel;
public int gpPoint;
void Start()
{
gpPoint = 0;
gpLabel = GetComponent<Text>();
gpLabel.text = "GP:" + gpPoint.ToString("D10"); // 0埋めの表示の仕方
}
public void AddGP(int amount)
{
gpPoint += amount;
gpLabel.text = "GP:" + gpPoint.ToString("D10");
}
}
![08d06f72 5ad5 4ece a9a5 35f7762b260e](https://codegenius.org/uploads/slide/image/3898/08d06f72-5ad5-4ece-a9a5-35f7762b260e.jpeg)
マネーポイントの獲得
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyHP : MonoBehaviour
{
public GameObject effectPrefab;
public AudioClip sound;
// ★追加
private GPManager gP;
public int gpPoint;
// ★追加
private void Start()
{
gP = GameObject.Find("GPLabel").GetComponent<GPManager>();
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Shell")
{
Destroy(gameObject);
GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
Destroy(effect, 0.3f);
AudioSource.PlayClipAtPoint(sound, transform.position);
// ★追加
gP.AddGP(gpPoint);
}
}
}
![D1205c73 21bc 46d7 80f6 a8c0394bfd95](https://codegenius.org/uploads/slide/image/3899/d1205c73-21bc-46d7-80f6-a8c0394bfd95.jpeg)
![59e54774 11a7 4f13 945a 5deb2fe6c67b](https://codegenius.org/uploads/slide/image/3894/59e54774-11a7-4f13-945a-5deb2fe6c67b.jpeg)
![5d57c349 9078 48b3 9220 46117cd4de74](https://codegenius.org/uploads/slide/image/3895/5d57c349-9078-48b3-9220-46117cd4de74.jpeg)
![F60cbc64 15ed 46ac 8e7c be7f1f42f2f8](https://codegenius.org/uploads/slide/image/3896/f60cbc64-15ed-46ac-8e7c-be7f1f42f2f8.jpeg)
![378c5d61 4d17 462f 8f9f 687f503dadc5](https://codegenius.org/uploads/slide/image/3897/378c5d61-4d17-462f-8f9f-687f503dadc5.jpeg)
獲得したマネーポイントの表示
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GPManager : MonoBehaviour
{
private Text gpLabel;
public int gpPoint;
void Start()
{
gpPoint = 0;
gpLabel = GetComponent<Text>();
gpLabel.text = "GP:" + gpPoint.ToString("D10"); // 0埋めの表示の仕方
}
public void AddGP(int amount)
{
gpPoint += amount;
gpLabel.text = "GP:" + gpPoint.ToString("D10");
}
}
![08d06f72 5ad5 4ece a9a5 35f7762b260e](https://codegenius.org/uploads/slide/image/3898/08d06f72-5ad5-4ece-a9a5-35f7762b260e.jpeg)
マネーポイントの獲得
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyHP : MonoBehaviour
{
public GameObject effectPrefab;
public AudioClip sound;
// ★追加
private GPManager gP;
public int gpPoint;
// ★追加
private void Start()
{
gP = GameObject.Find("GPLabel").GetComponent<GPManager>();
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Shell")
{
Destroy(gameObject);
GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
Destroy(effect, 0.3f);
AudioSource.PlayClipAtPoint(sound, transform.position);
// ★追加
gP.AddGP(gpPoint);
}
}
}
![D1205c73 21bc 46d7 80f6 a8c0394bfd95](https://codegenius.org/uploads/slide/image/3899/d1205c73-21bc-46d7-80f6-a8c0394bfd95.jpeg)
マネーポイント獲得システム