Minor Instantiation Issue

Okay so… a little bit baffled on an issue of instantiaton. Not sure that’s a word but I’m going with it.

Here’s the basics of the deal:

I have a code designed to allow the user to select how many of a certain structure to build. Logically, it seems as though they should all be instantiated at once, but rather progressively over a period of time, right? So, here’s the breakdown:

  • GUI buttons control how many to build.
  • The script accesses the master clock script to synchronize time.
  • Theoretically, the script below should instantiate a new object of type at regular intervals, right? The problem is, it doesn’t actually instantiate anything…
var targetDayNext : float = 0;
var startDayLF : float = 0;
var daysCounter : float = 0;

function BuildLightFactoryCountdown () {
    startDayLF = GalMap.GetComponent(MainScreenClock).days;
    targetDayNext = startDayLF + 3.0;
    if (daysCounter > targetDayNext) {
        Invoke ("BuildLightFactory", 0.0);
    }
}

function BuildLightFactory () {
    var lightFactory : GameObject = Instantiate(lightFactory);
    lightFactory.transform.parent = transform;
    startDayLF = 0;
    targetDayNext = 0;
    if (lightFactoryBuildCounter > 0) {
        Invoke ("BuildLightFactoryCountdown", 0.0);
    }
}

function Update () {
    daysCounter = GalMap.GetComponent(MainScreenClock).days;
}

You never call BuildLightFactoryCountdown except inside BuildLightFactory, which is only called from BuildLightFactoryCountdown

Sorry left a bit out in copying over…

var targetDayNext : float = 0;
var startDayLF : float = 0;
var daysCounter : float = 0;

function BuildLightFactoryCountdown () {
    startDayLF = GalMap.GetComponent(MainScreenClock).days;
    targetDayNext = startDayLF + 3.0;
    if (daysCounter > targetDayNext) {
        Invoke ("BuildLightFactory", 0.0);
    }
}

function BuildLightFactory () {
    var lightFactory : GameObject = Instantiate(lightFactory);
    lightFactory.transform.parent = transform;
    startDayLF = 0;
    targetDayNext = 0;
    if (lightFactoryBuildCounter > 0) {
        Invoke ("BuildLightFactoryCountdown", 0.0);
    }
}

function Update () {
    daysCounter = GalMap.GetComponent(MainScreenClock).days;
}

function OnGUI () {
if (GUI.Button (Rect (100, 80, 100, 20), "Build")) {
                          showLightFactoryBuild = false;
                          Invoke ("BuildLightFactoryCountdown", 0.0);
    }
}

[/code]

meh. figure it out yourself

I’m not sure what that would do … wouldn’t it just continually build one right after another?

/sigh

removed.

Right.

Why are you calling Invoke with a time of 0? My guess is that your conditional is never true.