0

I want to create a new gameobject like an enemy in a gameobject called EnemyController. Now I want to give the new enemies parameters when they are instantiated like speed and size, which vary from enemy to enemy. How do I do this? Should I simply use public variables and then set them after instantiation?

IceRevenge
  • 1,451
  • 18
  • 33
  • Possible duplicate of [In Unity, how can I pass values from one script to another?](https://stackoverflow.com/questions/13891892/in-unity-how-can-i-pass-values-from-one-script-to-another) – Draco18s no longer trusts SE Sep 22 '18 at 21:54

1 Answers1

2

Try something like this.

public class MyObject : MonoBehaviour
{
    /* Add parameters here */

    public void Initialize (/* Add parameters here */)
    {
        /* Add parameters here */
    }
}

And then on your EnemyController

MyObject newMyObject = (MyObject) Instantiate (newMyObjectPrefab);
newMyObject.Initialize (/* Add parameters here */);

Something like that will solve your problem.

Horothenic
  • 680
  • 6
  • 12