- Home /
Destorying game object not working
Hello, I am a new Unity user with some programming skills. Getting straight to the point I am making a game that when I press the shift key down "fire2" it creates a smallish wall in front of me and stops movement except turning. That works. but when I release the shift key up I want it to destroy the wall I just created. I have 3 objects. Character, Wall and Enemy.
on the character I have created a script called EnergyBlockFire and that code is;
//Variables - blockprefab is the wall - charPrefab is the character
var charPrefab:Transform;
var blockPrefab:Transform;
function Update ()
{
if(Input.GetButtonDown("Fire2")) // button down
{
Movement.blocking = true; //stopping movement
//spawns the wall
var bullet = Instantiate(blockPrefab,
gameObject.Find("WallSpawnPoint").transform.position,
Quaternion.identity);
}
//this bit works.. when I release the shift key it
//enables me to move which is what I want
if(Input.GetButtonUp("Fire2"))
{
Movement.blocking = false;
}
}
on the wall prefab I have created a script called EnergyBlockDestroy and the code is;
//enemy bullet collides with wall - this works
function OnTriggerEnter( hit : Collider)
{
if(hit.gameObject.tag == "enemyfireball")
{
Movement.blocking = false;
Destroy(gameObject);
Destroy(hit.gameObject);
}
}
how ever this is the bit I am stuck at, it doesn't destroy the wall, no errors at all, i can after that place more walls down but it wont let me. the wall is called "BlockWall" both prefab and object in the game. it is also tagged as wallblock.
function update ()
{
if (Input.GetButtonUp("Fire2"))
{
Destroy(gameObject);
}
}
I understand with this it may be confusing so I uploaded it to the internet incase anyone needs to download it to look for them self's. Please help I really don't know why its not working. thank you!
Game Download -
http://www.megaupload.com/?d=QZCKILYJ
thankyou!
i don't undertand :/ sorry what do you mean reformat?
BeggreenD$$anonymous$$ THAN$$anonymous$$YOU! :D I have no idea how you did that but thanks
Answer by Alec-Slayden · Jul 25, 2011 at 04:57 PM
Capitalize the "u" in your Update function :D
otherwise you're creating your own function that is never called.
That was the only issue I noticed come up in a quick runthrough of the level.
O$$anonymous$$G! so simple :'( thank you so much! it works I actually am so shocked that was it :( thought I was doing something big wrong :( thank you!
I often miss the simple things, because its the simplest things I'm sure I got right.
Please mark this answer if it's the one that solved your problem. Too many new users forget to accept answers, and then the thread helps no one later.
LOL! I formatted the code, with no brain attached. Didnt look at it, just wanted to help formatting it. LOL!