Hey guys, I really really need help on this. I created a 2-dimensional array that is editable in the inspector. The first array is “Waves,” (which allows me to choose how many waves my game has before you win) and the array inside “Waves” is “enemy” (which is a GameObject). Here is what it looks like in the inspector…
I am just simply trying to assign 3 variables to each GameObject that the array “enemy” holds, the variables being…
public int count;
public float lowRange;
public float highRange;
I want to do this so that I can edit these variables to however I choose for each enemy in the inspector. So I can enter the count, lowRange, and highRange for each enemy in the wave.
Here is a picture of the script for the called array “Waves.”
I have been trying to make the three declared variables visible in the inspector under each GameObject but it doesn’t show up. Please help I have been stuck for awhile now.
Variables inside methods cannot be public. They have to be at the class level.
I think what you want, is instead of Public GameObject Enemies;
I think you want to use public EnemyLoadSetup EnemyLoads;
With a class like this:
[System.Serializable]
public class EnemyLoadSetup // Not a monobehaviour
{
public GameObject[] EnemyType;
public int Count;
public float lowRange;
public float highRange;
}
So I think what @hpdvs2 was saying is instead of using an array of GameObjects you could have an array of Enemies.
[System.Serializable]
public class Enemy // Not a monobehaviour
{
public GameObject EnemyType;
public int Count;
public float lowRange;
public float highRange;
// Just make a constructor here
public Enemy ( GameObject enemy ,int _count, float _lowRange, float _highRange)
{
EnemyType = enemy;
Count = _count;
lowRange = _lowRange;
highRange = _highRange;
}
}
public class OtherClass
{
public int enemyCount;
public Enemy[] Enemies = new Enemy[enemyCount];
public GameObject enemyPrefab;
void Start()
{
/*Obviously this sets values for all the enemies but it would not be hard to customize for desired effect.
Just set the values in scripts and skip the editor(i think would be easier)
or alternatively you could set up the ints for different kinds of enemies in the
inspector. I.E( weakenemy has certain stats etc)
*/
for(int i = 0 ; i < Enemies.length; i++)
{
Enemies *= new Enemy(enemyPrefab,count,lowRange,highRange);*
}
}
}