Bacteria/Cell Growth
Hi there,
I am trying to code some basic bacterial growth into unity. I would each clone of my capsule to appear from the position of the clone that created it. However, at the moment all of my clones are simply appearing from the original clone. Here is the script I am using at the moment.
#pragma strict
var cube: GameObject;
var spawn_position;
var timer = 0.0;
function spawn_cube ()
{
spawn_position = cube.transform.position;
var temp_spawn_cube = Instantiate(cube, spawn_position, Quaternion.identity);
}
function Start () {
}
function Update () {
timer += Time.deltaTime;
if (timer > 10)
{
spawn_cube();
timer = 0.0;
}
}
Any help would be much appreciated!
Thanks very much :)
have you tried simply to change temp_spawn_cube position after instanciating?
Thanks very much I managed to fix this - it was very simple! Here is the code in case some one in the future wants to do a similar thing.
#pragma strict
var cube: GameObject;
var spawn_position;
var timer = 0.0;
var unit1 : GameObject;
function spawn_cube ()
{
spawn_position = Unit1.transform.position.x==3;
var temp_spawn_cube = Instantiate(cube, spawn_position, Quaternion.identity);
}
function Start () {
}
function Update () {
timer += Time.deltaTime;
if (timer > 10)
{
spawn_cube();
timer = 0.0;
Destroy (gameObject, 10);
}
}
spawn_position = Unit1.transform.position.x==3; What on earth is that supposed to mean?
spawn_position will become true if x is 3, false otherwise? And then you use that to represent position? That looks way wrong.
Answer by Statement · Nov 02, 2015 at 10:34 PM
Something like this?
function spawn_cube ()
{
spawn_position = cube.transform.position;
var clone = (GameObject) Instantiate(cube, spawn_position, Quaternion.identity);
var cloneScript = clone.GetComponent.<Bacteria>(); // Whatever your script is called.
cloneScript.cube = gameObject; // Make it clone from me
}