x


Restricting clone numbers.

The game i am working on is about spawning ramps in front of cars. i have a simple spawning script that works fine. but i want to restrict the amount of clones i can make, was wondering how. THanks.

more ▼

asked Aug 20 '11 at 06:26 AM

Naszia gravatar image

Naszia
1 10 13 15

This completely depends on your script really. Without knowing anything about it all I can say is that you'll have to keep track of the number of ramps you spawned and when you're about to place a new ramp you check if you've spawned more ramps than is allowed.

Aug 20 '11 at 11:32 AM reijerh
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

* SPAM *

more ▼

answered Aug 20 '11 at 01:52 PM

sdfwefwedfgherhr gravatar image

sdfwefwedfgherhr
-16

(comments are locked)
10|3000 characters needed characters left

This how I recently solved this problem:

var thePrefab : GameObject;
var MaxObjectCount = 0;


function Update () {

    if(Input.GetButtonUp("Fire2")){
    var instance : GameObject = Instantiate(thePrefab, transform.position, transform.rotation);
       instance.name = "boxSpawn";
         MaxObjectCount += 1;
         checkhit();  
    }
}

function checkhit(){
    if(MaxObjectCount == 16){
       Destroy(GameObject.Find("boxSpawn"));
       MaxObjectCount -=1;
    }
}

Where the var 'MaxObjectCount' adds one each time my Prefab spawns in the Update function, and in my 'checkhit' function I set it to destroy the first one I spawned after a set limit. So I can only have 15 clones at a time.

I'm fairly new and don't know if this is the best approach, but it works. I am now working on allowing the MaxObjectCount var to speak to the prefab so I can also keep track of the info to be able to do the same when I destroy my prefab via a collision.

I hope this helped.

more ▼

answered Aug 23 '11 at 12:56 AM

betabob gravatar image

betabob
1 1 2 3

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x440
x25

asked: Aug 20 '11 at 06:26 AM

Seen: 629 times

Last Updated: Aug 23 '11 at 12:56 AM