私はいくつかのデータを整理するクラスを作って、これらのクラスのいくつかの構成されたクラス(サブクラス?)ので、私はどのように把握することはできませんしかし、私のような...Unity3Dモノクラスのクラスからなるクラスをどのように参照しますか?
classA.classB.value = 1;
何かを行うことができています私のクラスを参照してください。どのように私はそれについて行く必要があるか知っていれば、それは素晴らしいだろう!
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
class Gene {
public string name;
public float value;
public float complexity;
public Gene() {
name = "";
value = 0;
complexity = 0;
}
public Gene(string Name, float Value, float Complexity) {
name = Name;
value = Value;
complexity = Complexity;
}
}
class Genome {
public Gene agility;
public Gene intelligence;
public Gene strength;
public Genome(){
agility = new Gene();
intelligence = new Gene();
strength = new Gene();
}
public Genome(Gene Agility, Gene Intelligence, Gene Strength) {
agility = Agility;
intelligence = Intelligence;
strength = Strength;
}
public IEnumerator GetEnumerator() {
return (IEnumerator)this;
}
}
public class Life : MonoBehaviour {
Genome genome; //Warning Life.genome is never assigned to, and will always have its default value null
Quantity quantity; //Warning Life.quantity is never assigned to, and will always have its default value null
void OnEnable() {
genome = /*???*/; //How do I add the reference?
quantity = /*???*/; //How do I add the reference?
genome.agility.name = "Agility"; //On Runtime: NullReferenceException: Object reference not set to an instance of an object
genome.agility.complexity = 100;
genome.intelligence.name = "Intelligence";
genome.intelligence.complexity = 1000;
genome.strength.name = "Strength";
genome.strength.complexity = 100;
}
}
'Genome'と' Quantity'は 'AudioClip'の子孫ではありません。 OPの誤解を避けるためにいくつかの改訂を検討してください。 – Serlite
実際にそれらを '新しいゲノム()/数量()'にするといいですよね) –
@Serliteこれは私が私の側にスクリプトを持っていないのでコンパイルするのに使ったタイプミスです。ゲノムとゲノムに変更するのを忘れました – Programmer