###前提・実現したいこと
unity c#で各チームのオブジェクト同士が戦うゲームを作っています。
###発生している問題・エラーメッセージ
以下のコードにあるtargetのスクリプトにある変数を使いたいのですが、どうすればいいのでしょうか。
###該当のソースコード
c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class blackAttack : MonoBehaviour { 6 public GameObject target; 7 public string enemy1; 8 public string enemy2; 9 public float timeBetweenAttacks = 0.5f; 10 public int attackDamage = 10; 11 12 UnityEngine.AI.NavMeshAgent nav; 13 Vector3 destination; 14 GameObject[] a; 15 GameObject[] b; 16 bool targetInRange; 17 float timer; 18 float eD; 19 20 void FixedUpdate(){ 21 target = null; 22 float minDis = 9999f; 23 a = GameObject.FindGameObjectsWithTag (enemy1); 24 b = GameObject.FindGameObjectsWithTag (enemy2); 25 26 foreach(GameObject go in a){ 27 if(go == null){ 28 continue; 29 } 30 eD = Vector3.Distance (transform.position, go.transform.position); 31 if(eD < minDis){ 32 minDis = eD; 33 destination = go.transform.position; 34 target = go; 35 } 36 } 37 38 foreach(GameObject go in b){ 39 if(go == null){ 40 continue; 41 } 42 eD = Vector3.Distance (transform.position, go.transform.position); 43 if(eD < minDis){ 44 minDis = eD; 45 destination = go.transform.position; 46 target = go; 47 } 48 } 49 50 51 } 52 53 54} 55
###試したこと
###補足情報(言語/FW/ツール等のバージョンなど)
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。