title: Unity - pass parameters on instantiation
body: <p>I made a simple <em>message box</em> that should show a message to the user. It's a prefab and does a couple of things, mostly animations <strong>upon instantiation</strong>. To run code upon instantiation I used the <code>Start()</code> function. 
  It worked when I already knew what to message but I need something like a <code>constructor</code>, that runs before <code>Start()</code>, but upon <code>instantiation</code> and can take parameters.
  Now, I'm fully aware that I could instantiate, set the message and run everything - so using 3 lines of code where I instantiate it, but I'm curious if there is another, more proper solution? All I found on the net was that instantiate, then do something. </p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>My calling of a messagebox to show up:</p>
  
  <pre><code>var timeBox =
      Instantiate(messageBox, penaltySpawnLoc.position, penaltyPrefab.transform.rotation, transform);
      var scr = timeBox.GetComponent&lt;MessageBox&gt;();
      scr.OnCreated(message);
  </code></pre>
  
  <p><code>OnCreated</code> does the initialization, show up animations, so basically everything.
  But it <em>needs</em> a <code>string</code> input to know what to show up and I don't want to set the text value "on the fly" - it would make appear some weird flickering when the messagebox is visible but the text isn't set. </p>
  
  <p><strong>EDIT2:</strong></p>
  
  <p>the last parameter <code>transform</code> in the <code>Instantiation</code> is the <code>Canvas</code> this script is on as this is a UI script. That parameter means that the freshly instantiated <code>GameObject</code> is the child of that.</p>
  
  <p><strong>EDIT3:</strong></p>
  
  <p>timeBox is just an instance of <code>messageBox</code>, they are <code>GameObject</code>s. 
  One message box is used <strong>only once.</strong> Its purpose is to appear with the message and after like 0.5 seconds fade out and move away. After moving away it destroys itself. </p>