- Home /
MonoBehavior.Start() called infinite times?
So, I'm running a simple instantiate() script to duplicate gameObject, genOrig once on a random point between 4 and -4 on the X-Axis. Simple enough, right? However, when I start the script, Unity creates a clone of the game object every frame, like an Update() message.
Here's my code: using UnityEngine; using System.Collections;
public class GenerationScript : MonoBehaviour {
public GameObject genOrig;
public Quaternion rot;
public float posX = Random.Range(-4f, 4f);
// Use this for initialization
void Start () {
Vector3 position = new Vector3 (posX, 0, 0);
Instantiate (genOrig, position, rot);
}
// Update is called once per frame
void Update () {
}
}
I suspect something strange is calling Start() every frame. Help please?
OOOOOHHHHH! god i didn't know that. What would I attatch the script to? the scene?
Answer by Lo0NuhtiK · Mar 26, 2014 at 12:49 AM
If you're instantiating a gameObject with this script attached to it, every time the new object Start()'s it makes a new one, and so-on...
Your answer
Follow this Question
Related Questions
Initialising List array for use in a custom Editor 1 Answer
gameObject are not referenced 2 Answers
Can I use AddComponent to add (this.script) to an object? 1 Answer
Rotating a Vector3 in Instantiation 1 Answer
Distribute terrain in zones 3 Answers