Can't get Properties from Another class object.
Hi Guys! I need you help.
I'm trying to create fishing game, and have a problem.
I have some types of the fish, and have some type of the baits.
I'm want to manage "bait influence" in the inspector for each of fishes for each of baits for example using "Range(0,1)"
First of All i want show in "Fish" object inspector all available Baits and "influence" field for each one bait.
I think the simplest way to do it, include "Baits folder" to each of fishes. But i want to do it using script, if is's possible
I Can get and show "Objects" of Bait Class - see here http://joxi.ru/krD6OwEtEGPeP2
But i don't understand how i can show this elements properties (fields).
code Fish class here - http://joxi.ru/eAOX7vKTxv137r
i need something like - public float[] baitInfluence; in Fish Class for each of bait.
Answer by Hellium · Jul 24, 2018 at 07:29 AM
public float[] baitInfluence ;
void OnEnable()
{
// ...
baitsGO = GameObject.Find("Baits");
baits = baitsGO.GetComponentsInChildren<Bait>();
baitInfluence = new float[baits.Length] ;
for( int i = 0 ; i < baitInfluence.Length ; ++i )
baitInfluence[i] = baits[i].influence ;
}
Note : Next time, please, include your code using the 101010
button and the image of the inspector using the provided image uploader.