- Home /
Call a Function when Object Created
Hello Everybody,
I have a "Uret Function" this function's task is print i values to console how can i call and start this function when i create a object? I want this function will start working when i create a cube?
var Object : GameObject; var i : int;
function Uret() { while (i < 6) { if(i==5) { // } else { // yield WaitForSeconds (5); print(i); } i++; } }
Thank you for your help
Regards
Vincenzo
Answer by Ray-Pendergraph · Jul 28, 2010 at 05:20 PM
To invoke functionality on a MonoBehaviour after instantiation use the Awake or Start methods. These have distinct implications but both get called after Unity creates the object. These are documented here.
Answer by Eric5h5 · Jul 28, 2010 at 07:35 PM
var scriptInstance = Instantiate(myPrefab).GetComponent(ScriptName);
scriptInstance.Uret();
Your answer
Follow this Question
Related Questions
Call function after script compilation? 2 Answers
calling a function from non attached other script 1 Answer
How to call a function from another script without referencing it? 1 Answer
how do I make a Object getcomponent and call a function 1 Answer
Function being called on multiple objects when just one is clicked 1 Answer