Hey i am using this script and want to be able to restrict how many clones i can spawn. i am spawning ramps and only want the player to be able to spawn say 5 per level. and when they run out they simple cant use anymore. THanks
var projectile : Rigidbody;
var speed = 0;
function Update() {
if( Input.GetButtonDown( “Fire1” ) ){
var instantiatedProjectile : Rigidbody = Instantiate( projectile, transform.position, transform.rotation );
Pretty Simple. Just create a var max_projectiles and another var projectile_count and then set it, to say, 5. then check if it is equal to 5 after pressing the button, if its not, add 1 to it. For example:
var projectile : Rigidbody;
var max_projectiles = 5;
var projectile_count = 0;
var speed = 0;
function Update() { if( Input.GetButtonDown( "Fire1" ) ){
if (projectile_count <= max_projectiles)
{
var instantiatedProjectile : Rigidbody = Instantiate( projectile, transform.position, transform.rotation );
instantiatedProjectile.velocity = transform.TransformDirection( Vector3( 0, 0, speed ) );
Physics.IgnoreCollision( instantiatedProjectile.collider , transform.root.collider );
projectile_count++
}
}}
not tested so dont know if it will work. tweak it, its really simple.