I have attached the following script to a number of weapon prefabs:
public class WeaponScript : MonoBehaviour {
public enum Direction {Right, Straight, Left};
public Direction weaponDir;
void Start () {
prepareDirection (weaponDir);
}
void prepareDirection(Direction dir) {
if (dir == Direction.Straight) {
transform.localEulerAngles = new Vector3 (0, 0, 0);
}
else if(dir == Direction.Left) {
transform.localEulerAngles = new Vector3 (0, 0, -30);
}
else if(dir == Direction.Right) {
transform.localEulerAngles = new Vector3 (0, 0, 30);
}
}
}
I also added the following script to an empty game object SetupWeapon:
public class SetupWeaponsScript : MonoBehaviour {
public GameObject[] weaponPrefabs;
public GameObject[] weapons;
void Start ()
{
weapons = new GameObject[weaponPrefabs.Length];
for (int i = 0; i < weaponPrefabs.Length; i++)
{
weapons[i] = Instantiate(weaponPrefabs[i]) as GameObject;
}
}
}
When I select my SetupWeapon object, I am able to populate the weaponPrefabs
array with the weapon prefabs I want to use, but I can't directly alter their parameters in that same inspector view. I want to be able to override the direction of each weapon prefab in the list, rather than use the value that's stored on the prefab itself.
How can I create the weaponsSetupScript
in such a way that I can set the direction enum for each weapon entry at the same time that I set select the prefab in the editor? I believe it might have something to do with inheritance, just not too sure how to go about it though.
weaponDir
in the Inspector for theWeaponScript
class, and then they'll be instantiated with the value you've set. Is it that you want to override this direction after instantiating the prefabs? You can do this by storing and instantiating the prefabs as theWeaponScript
type rather thanGameObject
, or by usingGetComponent
to access theirWeaponScript
on demand. Or is there some other issue here? \$\endgroup\$weaponPrefabs
using the editor. Something like a tuple of the weapon prefab and theDirection
enum. \$\endgroup\$