ユーザーのHPを表示するのにSliderをつかっているのですがプレハブからでた敵がDestroyした時にユーザーのHPをへらしたいのですがうまくいきません。
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class HP : MonoBehaviour { public Slider slider; private float life = 10.0f; void Start () { } void Update () { } public void HPChange(float value){ slider.value = life - value; life -= value; } } コード
using System.Collections; using System.Collections.Generic; using UnityEngine; public class a : MonoBehaviour { public HP hp; private float speedChangeTime = 0.0f; public GameObject b; void Update () { speedChangeTime += Time.deltaTime; if (speedChangeTime > 7.5f) { Destroy (this.gameObject); hp.HPChange (2.0f); } } コード プレハブにアタッチ
the the game object 'Slider' is inactive!というのがhp.HPChange (2.0f);にときに出てしまいます。
回答1件
あなたの回答
tips
プレビュー