スコア判定がうまく出来ない
Unityでプレイヤーの手にオブジェクト(銃など)を持たせてを
プレイヤーに向かってくる敵やスライム(cube作成)などを攻撃して
スコア判定を出るようにしようとしてるのですが、スコア判定の
参考サイトや本を参考にしても判定がうまくできません。
調べたところ、スコア表示だけだったりしてよくわからずお助けを願いします。
敵やスライム等ははプレハブ化したものを使用していて、
以下のスクリプトをアタッチしているのですが
scoreのC#
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; [RequireComponent(typeof(Text))] public class Score : MonoBehaviour { Text uiText; public Text scoreText; //Text用変数 public int Points { get; private set; } //スコア計算用変数 void Start() { uiText = GetComponent<Text>(); } public void AddScore(int addPoint) { //加算 Points += addPoint; //更新 uiText.text = string.Format("score:{0:D3}", Points); } }
プレハブ化してるオブジェクトのC#
using UnityEngine; [RequireComponent(typeof(AudioSource))] public class Enemy : MonoBehaviour { [SerializeField] int point = 1; //倒れた Score score; // Start is called before the first frame update void Start() { //ge-mu var gameObj = GameObject.FindWithTag("Score"); //konpone score = gameObj.GetComponent<Score>(); } void GoDown() { //スコア判定 score.AddScore(point); } }
プレイヤーがオブジェクトに触れた時の判定やオブジェクトが消えるところまでは出来てます。ただスコア判定だけが出来ずエラーコードもありません。
オブジェクトは自動生成です。
補足情報
Unity 2018.3.5.
あなたの回答
tips
プレビュー