Es klingt vielleicht dumm, aber wie kann ich eine Klasse von einem Skript in Kind in einem anderen Skript in Eltern verweisen? Ich kann nichts auf Google finden. Hinweis: Es gibt paar Fehler in meinem Skript, das ist nicht der Punkt des Posts.Wie eine Klasse von Kind zu Eltern verweisen?
//Public
//Private
private Rigidbody myRigidbody;
private Renderer myRenderer;
private Material tileDefaultMaterial;
private Material tileSelectedMaterial;
private Material tileSameGroupMaterial;
void Start() {
myRigidbody = GetComponent<Rigidbody>();
myRenderer = GetComponent<Renderer>();
tileDefaultMaterial = Resources.Load ("TileDefault", typeof(Material)) as Material;
tileSelectedMaterial = Resources.Load ("TileSelected", typeof(Material)) as Material;
tileSameGroupMaterial = Resources.Load ("TileSameGroup", typeof(Material)) as Material;
}
void Update() {
}
public class TileClass {
public int tileGroup = 0; //Indicates the Tile Group Number.
}
//Public
public GameObject[] allTiles; //Aray of all Tile GameObject.
public bool tileIsSelected = false; //If a Tile is Selected.
public int selectedTileGroup = 0; //Indicates the Selected Tile Group Number.
public int tileGroup = 0; //Indicates the Tile Group Number.
//Private
void Start() {
allTiles = new GameObject[transform.childCount];
for(int i = 0; i < transform.childCount; i++){
allTiles [i] = transform.GetChild (i).gameObject;
}
}
void Update() {
}
void OnMouseDown(){
RaycastHit hitInfo = new RaycastHit();
bool hit = Physics.Raycast (Camera.main.ScreenPointToRay (Input.mousePosition), out hitInfo);
if (hitInfo.transform.gameObject.tag == "Tile" && tileIsSelected == false) {
Debug.Log ("A Tile is Selected!");
tileIsSelected = true;
selectedTileGroup = ;
for(int i = 0; i < allTiles.Length; i++){
if (this.tileGroup == selectedTileGroup) {
allTiles [i].GetComponent<Renderer>().material = tileSameGroupMaterial;
}
}
myRenderer.material = tileSelectedMaterial;
} else if (hitInfo.transform.gameObject.tag == "Tile" && tileIsSelected == true) {
Debug.Log ("Second Tile is Clicked! (Should Swap them!)");
myRenderer.material = tileDefaultMaterial;
}
}
Sie können das nicht tun. Ihre Klasse erbt bereits von MonoBehaviour. Was genau möchten Sie erreichen? –
Bitte geben Sie keinen Code als Bilder an. Siehe http://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors – gus27
Ich möchte eine Klasse mit einigen Variablen für jede Kachel erstellen und sie dann aus dem Manager-Skript verwalten. Ich bin mir nicht sicher, ob das der beste Weg ist. Ich bin neu in C# und Unity. – N1ckGreek