Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by slayer29179 · Jul 25, 2011 at 12:17 PM · movementgameobjectdestroykeypress

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!


Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Waz · Jul 25, 2011 at 12:36 PM 0
Share

Please reformat. I can't read that.

avatar image slayer29179 · Jul 25, 2011 at 12:37 PM 0
Share

i don't undertand :/ sorry what do you mean reformat?

avatar image BerggreenDK · Jul 25, 2011 at 12:51 PM 0
Share

I've reformatted his code-sections now.

avatar image slayer29179 · Jul 25, 2011 at 12:58 PM 0
Share

BeggreenD$$anonymous$$ THAN$$anonymous$$YOU! :D I have no idea how you did that but thanks

avatar image slayer29179 · Jul 25, 2011 at 01:32 PM 1
Share

wow :) thank you :D

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image slayer29179 · Jul 25, 2011 at 06:11 PM 0
Share

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!

avatar image Alec-Slayden · Jul 25, 2011 at 06:16 PM 0
Share

I often miss the simple things, because its the simplest things I'm sure I got right.

avatar image Jason B · Jul 25, 2011 at 06:20 PM 1
Share

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.

avatar image BerggreenDK · Jul 25, 2011 at 09:51 PM 1
Share

LOL! I formatted the code, with no brain attached. Didnt look at it, just wanted to help formatting it. LOL!

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Move object, then destroy it. 1 Answer

Destroy(gameObject) does not work 2 Answers

Why are these object passing through each other? 1 Answer

How to let a GameObject move? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges