Hey guys Im writing a script that counts how many turrets there are If there are no more turrets it destroys a gate but I cannont figure what does it say in java when a object was destroyed? heres my code
var TurretNumber: int = 10;
var TurretType : Transform;
function Update ()
{
if (TurretNumber == 0)
{
Destroy(gameObject);
}
}
Mike_L
January 8, 2011, 1:25am
2
what i did is whenever the turret is destroyed, the turret number would lose one number. so put his in the place with the death stuff related to the turret controllingScript.turretNumber -= 1; and in the controlling script use static var turretNumber : int = 10;
So Your saying put the The TurretType Var into:
var explosion : Transform;
function OnTriggerEnter(hit : Collider )
{
if(hit.gameObject.tag == "ApcProjectile")
{
Destroy(hit.gameObject);
var exp = Instantiate(explosion, gameObject.transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
But JM what if I it want to affect a diffrent type of turret?
Call a function on the turret instead of using Destroy.
StuffThatBreaksTurrets
if ( hit.gameObject ) {
var turret : Turret = hit.gameObject.GetComponent(turret);
if ( turret ) {
turret.Destroy();
}
}
Turret.js
static var turrets : int;
function Start() {
turrets++;
}
function Destroy() {
Destroy( gameObject );
turrets--;
}
Then any object can ask how many Turrets remain with “if ( Turret.turrets == 0 )” or whatever.
I mean By that your saying to put the script with the turret control script and the turret death script
but what if I want a diffrent turret destroyed to get the gate destroyed
Mike_L
January 8, 2011, 3:06am
8
no, you do this:
static var turretNumber: int = 10;
var turretType : Transform;
function Update ()
{
if (turretNumber == 0)
{
Destroy(gameObject);
}
}
and then you put the -= part in the turret script like you had it.
Ok how about this:
var TurretNumber: int = 10;
var TurretType : Transform;
function Update ()
{
if (TurretNumber == 0)
{
Destroy(gameObject);
}
}
function Destroy()
{
if (TurretType != null)
{
TurretNumber -= 1;
Debug.Log(what will go in the debug log?)
}
}
Mike_L
January 8, 2011, 3:51am
10
why are you calling the destroy function in the “gameManager” script? just do this:
static var turretNumber: int = 10;
var turretType : Transform;
function Update ()
{
if (turretNumber == 0)
{
Destroy(gameObject);
}
}
var explosion : Transform;
function OnTriggerEnter(hit : Collider )
{
if(hit.gameObject.tag == "ApcProjectile")
{
SendMessage("Destroy");
}
}
function Destroy () {
Destroy(hit.gameObject);
var exp = Instantiate(explosion, gameObject.transform.position, Quaternion.identity);
Destroy(gameObject);
controllingScript.turretNumber -= 1;
}
would it be possible to do it without the destroy function? like this:
var explosion : Transform;
function OnTriggerEnter(hit : Collider )
{
if(hit.gameObject.tag == "ApcProjectile")
{
Destroy(hit.gameObject);
var exp = Instantiate(explosion, gameObject.transform.position, Quaternion.identity);
Destroy(gameObject);
LevelGateControl.TurretNumber -= 1;
}
}
Mike_L
January 8, 2011, 4:46am
12
yes, that would work fine
Ok now before I end the thread how do I make it so I can change values of how many I want gone?
Mike_L
January 8, 2011, 4:55am
15
use this script instead:
var explosion : Transform;
var turretValue = 1;
function OnTriggerEnter(hit : Collider )
{
if(hit.gameObject.tag == "ApcProjectile")
{
Destroy(hit.gameObject);
var exp = Instantiate(explosion, gameObject.transform.position, Quaternion.identity);
Destroy(gameObject);
LevelGateControl.TurretNumber -= turretValue;
}
}
then you can change the turret value
Well its not working becuase when I apply it to levelGate A number does not show that will let me change it
Mike_L
January 8, 2011, 5:06am
17
that is because it is a static variable, if it is static, you cant edit it that way. you have to do that through the script.
Mike_L
January 8, 2011, 5:07am
18
its like private var, except its public
Mike_L
January 8, 2011, 5:15am
19
try this:
static var turretNumber: int;
var turretType : Transform;
var turrets = 10;
function Update () {
if (turretNumber == 0)
{
Destroy(gameObject);
}
}
function Awake () {
turretNumber = turrets;
}
I know that and it was a static. Im wondering what could be the problem here is my code:
static var TurretNumber : int = 10;
function Update ()
{
if (TurretNumber == 0)
{
Destroy(gameObject);
}
}
And the on Turret collison:
[var explosion : Transform;
function OnTriggerEnter(hit : Collider )
{
if(hit.gameObject.tag == "ApcProjectile")
{
Destroy(hit.gameObject);
var exp = Instantiate(explosion, gameObject.transform.position, Quaternion.identity);
Destroy(gameObject);
LevelGateControl.TurretNumber -= 1;
}
}