Unityでゲームを作っているところなのですが、スコアが加算されません。プログラミングは以下の通りです。
メソッドは呼び出されますが、代入ができません。原因は何でしょうか。
呼び出される側
C#
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class GameDirector : MonoBehaviour { GameObject pointText; int point = 0; public void get100(){ this.point += 100; } public void get500(){ this.point += 500; } public void get1000(){ this.point += 1000; } public void get5000(){ this.point += 5000; } // Use this for initialization void Start () { this.pointText = GameObject.Find ("Point"); } // Update is called once per frame void Update () { this.pointText.GetComponent<Text> ().text = this.point.ToString () + " point"; } }
get〇〇〇を呼び出す側
c#
using UnityEngine; using System.Collections; using System.Collections.Generic; public class TestTarget : MonoBehaviour { public Texture2D cursor; // カーソルに使用するテクスチャ public AudioClip shot; private AudioSource audioSource; GameObject director; void Start () { // カーソルを自前のカーソルに変更 Cursor.SetCursor (cursor, new Vector2 (cursor.width / 2, cursor.height / 2), CursorMode.ForceSoftware); audioSource = gameObject.GetComponent<AudioSource> (); this.director = GameObject.Find ("GameDirector"); } void Update () { // マウスの左クリックで撃つ if(Input.GetButtonDown("Fire1")) { Shot(); if (Input.GetMouseButtonDown (0)) { audioSource.PlayOneShot (shot); } } } // 敵を撃つ void Shot() { Ray ray2 = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit2; if(Physics.Raycast(ray2, out hit2, 100f, LayerMask.GetMask("Enemy"))) { if (Physics.Raycast(ray2,out hit2)){ if (hit2.collider.tag == "100"){ this.director.GetComponent<GameDirector>().get100(); Debug.Log ("+100"); }else if(hit2.collider.tag == "500"){ this.director.GetComponent<GameDirector>().get500(); Debug.Log ("+500"); }else if(hit2.collider.tag == "1000"){ this.director.GetComponent<GameDirector>().get1000(); Debug.Log ("+1000"); }else if(hit2.collider.tag == "5000"){ this.director.GetComponent<GameDirector>().get5000(); Debug.Log ("+5000"); } Destroy(hit2.collider.gameObject); } } } }
まだ回答がついていません
会員登録して回答してみよう