|
This should be fairly trivial and I don't know what's wrong with my script. I seem to have trouble understanding how to send http://messages.My gamemanager script keeps track of the number of prefabs and has two functions that are called when a prefab is created/destroyed. I checked that both CountPlatformsUp() and CountPlatformsDown() are called, but my "platforms" variable doesn't keep track and once destroyed platforms are not spawned in Update(). Why? From the prefab:The gamemanager:
(comments are locked)
|
|
Is the game manager script called "_gamemanagerScript.js"? You should pass the script name without quotes or extension to GetComponent - if the name is "GameManagerScript.js", use GetComponent(GetManagerScript). Anyway, there's a good method to keep track of the current population of platforms: create an empty object, call it "Platforms", reset its position and rotation and assign the script below to it. Whenever a new platform is created, it's childed to the Platforms object - this way you can just check childCount to know how many platforms are alive (Unity always updates the childCount when a child is added or destroyed).
var platformPrefab : GameObject;
var spawnAreaObject : GameObject;
private var spawnAreaTransform;
function Start () {
spawnAreaTransform = spawnAreaObject.transform; // get transform directly
}
function Update () {
if (transform.childCount Very cool. Thanks. Will do that. I wonder though why my initial and messy script wasn't working correctly.
Jan 21 '12 at 10:19 AM
Nicolinux
(comments are locked)
|

aldonaletto already gives you a better solution for your problem, but your original way have some problems:
In the "_gameManagerScript.js" script:
In your platform script:
Many thanks for the suggestions. To my defense - I am coding a quick prototype, thus the messy coding. Should have mentioned it. I'd like to understand why the "if (platforms <= 20)" does not get called in Update(). Any ideas?