임 매우 프로그래밍에 새로운 나는 발생하는 문제를 해결하는 데 도움이 필요합니다. 다른 스크립트의 배열에 액세스하려고하는데 일반적으로 문제가 없습니다. 그러나이 IST 내 상황 : 예를 들어변수 이름을 가진 다른 스크립트의 배열에 액세스합니까?
:
스크립트 A는 다른 숫자 이외의 이름으로 몇 가지 배열이 포함되어 있습니다.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ScriptA : MonoBehaviour {
public int[] keys = new int[4];
public int[] screws= new int[4];
public int[] nails= new int[4];
public int[] iron= new int[4];
....
}
이제 스크립트 B에서 변수를 사용하여 이러한 배열에 액세스해야합니다. 내가 어떻게 할 수 있니? 예를 들어
: 아이디어와 솔루션
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ScriptB: MonoBehaviour {
ScriptA scriptA;
public string arrayName; // Here user could type in the name of an array
void Start()
{
scriptA = GameObject.Find("Object").GetComponent<ScriptA>();
// This try to access the array of course not works. But how?
scriptA.arrayname;
}
감사합니다. 나는 그 어려운 문제는 아니라고 생각한다. 그러나 나는 그것을 해결할 생각이 없다.
예를 들어'keys'에 액세스하려면'scriptA.keys' 또는 개별 요소'scriptA.keys [0]'을 사용하십시오. –
그래,하지만 난 ScriptB에서 문자열 변수 "arrayName"로 배열에 액세스해야합니다 – ToboTheRibbler