Instantiateしたオブジェクトに、Sendmessageで数値(hitpoints)を与えたいのですが、上手くいきません。シーン上では(Clone)と表示されています。
元々あるプレハブにはSendmessage出来ているのですが、Instantiateしたオブジェクトだと出来ません。
どう書き換えればいいでしょうか? 回答よろしくお願いします。
C#
1 2//生成させるスクリプト 3 4using System.Collections; 5using System.Collections.Generic; 6using UnityEngine; 7 8public class Appear : MonoBehaviour { 9 10 public GameObject Enemy;//出現させるプレハブ 11 public int max;//出現させる人数 12 public int appear;//出現した数 13 static Vector3 pos;//出現させる座標位置 14 public float x; 15 public float z; 16 17 // Use this for initialization 18 void Start () { 19 appear = 0; 20 21 } 22 23 // Update is called once per frame 24 void Update () { 25 if (max > appear) 26 { 27 Appear001(); 28 } 29 } 30 31 void Appear001() 32 { 33 x = Random.Range(0, 1000f); 34 z = Random.Range(0, 1000f); 35 pos = new Vector3(x, 0, z); 36 Instantiate(Enemy, pos, Quaternion.identity); 37 appear++; 38 } 39}
c#
1//中略 2 3//Sendmessageを受け取るスクリプト 4 5void DeductPoints(int hitpoints) 6 { 7 if (End == true) 8 { 9 return; 10 } 11 12 Characterhealth -= hitpoints; 13 14 if(Characterhealth < 50) 15 { 16 audiosource.clip = audioClip1; 17 audiosource.Play(); 18 Blood.SetActive(true); 19 Invoke("BloodOff", 1f); 20 CharacterHate += 20; 21 } 22 23 if (Characterhealth < 40) 24 { 25 26 Blood.SetActive(true); 27 } 28 29 if (Characterhealth < 30) 30 { 31 32 Blood.SetActive(true); 33 } 34 35 if (Characterhealth < 20) 36 { 37 38 Blood.SetActive(true); 39 } 40 41 if (Characterhealth < 10) 42 { 43 44 Blood.SetActive(true); 45 } 46 47 }
C#
1 2//Sendmessageを送るスクリプト 3 4using System.Collections; 5using System.Collections.Generic; 6using UnityEngine; 7 8public class AttackScript : MonoBehaviour 9{ 10 public float TheDistance; 11 public GameObject Player; 12 public GameObject agent; 13 14 15 16 public int hitpoints = 10; 17 18 bool End = false; 19 20 // Use this for initialization 21 void Start() 22 { 23 24 } 25 26 // Update is called once per frame 27 void Update() 28 { 29 if (agent == null) return; 30 31 Vector3 Apos = Player.transform.position; 32 33 Vector3 Bpos = agent.transform.position; 34 35 36 37 TheDistance = Vector3.Distance(Apos, Bpos); 38 39 if (Input.GetButtonDown("Fire1")) 40 { 41 if (TheDistance <= 4) 42 { 43 44 GameObject.FindGameObjectWithTag("People").SendMessage("DeductPoints", hitpoints, SendMessageOptions.DontRequireReceiver); 45 46 47 } 48 } 49 50 51 } 52 53}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/12/18 17:25