Unityでゲームを作っているところなのですが、スコアが加算されません。プログラミングは以下の通りです。
メソッドは呼び出されますが、代入ができません。原因は何でしょうか。
呼び出される側
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5 6public class GameDirector : MonoBehaviour { 7 GameObject pointText; 8 int point = 0; 9 10 public void get100(){ 11 this.point += 100; 12 } 13 14 public void get500(){ 15 this.point += 500; 16 } 17 18 public void get1000(){ 19 this.point += 1000; 20 } 21 22 public void get5000(){ 23 this.point += 5000; 24 } 25 26 // Use this for initialization 27 void Start () { 28 this.pointText = GameObject.Find ("Point"); 29 } 30 31 // Update is called once per frame 32 void Update () { 33 this.pointText.GetComponent<Text> ().text = 34 this.point.ToString () + " point"; 35 } 36} 37
get〇〇〇を呼び出す側
c#
1using UnityEngine; 2using System.Collections; 3using System.Collections.Generic; 4 5 6public class TestTarget : MonoBehaviour { 7 8 9 public Texture2D cursor; // カーソルに使用するテクスチャ 10 11 public AudioClip shot; 12 private AudioSource audioSource; 13 14 GameObject director; 15 16 17 void Start () { 18 // カーソルを自前のカーソルに変更 19 Cursor.SetCursor (cursor, new Vector2 (cursor.width / 2, cursor.height / 2), CursorMode.ForceSoftware); 20 21 audioSource = gameObject.GetComponent<AudioSource> (); 22 23 this.director = GameObject.Find ("GameDirector"); 24 } 25 26 void Update () { 27 // マウスの左クリックで撃つ 28 if(Input.GetButtonDown("Fire1")) { 29 Shot(); 30 31 if (Input.GetMouseButtonDown (0)) { 32 audioSource.PlayOneShot (shot); 33 } 34 35 } 36 37 38 } 39 40 // 敵を撃つ 41 void Shot() { 42 Ray ray2 = Camera.main.ScreenPointToRay(Input.mousePosition); 43 RaycastHit hit2; 44 if(Physics.Raycast(ray2, out hit2, 100f, LayerMask.GetMask("Enemy"))) { 45 if (Physics.Raycast(ray2,out hit2)){ 46 if (hit2.collider.tag == "100"){ 47 this.director.GetComponent<GameDirector>().get100(); 48 Debug.Log ("+100"); 49 }else if(hit2.collider.tag == "500"){ 50 this.director.GetComponent<GameDirector>().get500(); 51 Debug.Log ("+500"); 52 }else if(hit2.collider.tag == "1000"){ 53 this.director.GetComponent<GameDirector>().get1000(); 54 Debug.Log ("+1000"); 55 }else if(hit2.collider.tag == "5000"){ 56 this.director.GetComponent<GameDirector>().get5000(); 57 Debug.Log ("+5000"); 58 } 59 Destroy(hit2.collider.gameObject); 60 } 61 } 62 63} 64}