マネーポイント獲得システム




獲得したマネーポイントの表示
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");
}
}

マネーポイントの獲得
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);
}
}
}





獲得したマネーポイントの表示
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");
}
}

マネーポイントの獲得
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);
}
}
}

マネーポイント獲得システム