Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
2
Question by TerryN · May 03, 2010 at 04:33 AM · collisionobjectdestroyswitch

Destroying Gate by hitting a switch

Hey all,

I'm very new to scripting and Unity in general. I'm trying to create a level where the player would hit a switch and it would destroy a gate blocking the way to the end of the level.

var Gate : GameObject; var Key : GameObject; var isSwitch = false; var isKeyHit = false;

function Update() {
if (isKeyHit == true) { Destroy(Gate); } } function OnCollisionEnter(collision : Collision) { if (isSwitch){ isKeyHit = true; Destroy(Key); } }

Above is the script I wrote, I'm using the First Person prefab for my character and I have a capsule placed on the map to act as the switch and a cube for the gate which both have the above script attached to it. It doesn't work though :(

Can anyone help me out with this, all it needs to do is have the player hit that switch/key so that the gate is destroyed

Any help would be greatly appreciated

Comment
Add comment · Show 3
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 Cyclops · May 05, 2010 at 12:47 AM 0
Share

@TerryN, it's nice that you checkmarked the answer, but remember you can also upvote answers, here and anywhere else, that you think are good.

avatar image TerryN · May 05, 2010 at 02:27 PM 0
Share

@Cyclops sorry, still a noob lol. I clicked the arrow above the #1 on the answer which turned it into a 2, I'm guessing that's what you mean by upvoting.

avatar image Cyclops · May 05, 2010 at 11:06 PM 0
Share

@TerryN, yes, that's, thanks for doing it.

1 Reply

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

Answer by spinaljack · May 03, 2010 at 11:47 AM

One of the objects needs a non-kinematic rigid body to register a collision. Might be better to keep key values in one object like the player to keep track of things.

You can do an OnCollisionEnter(other:Collision){ SendMessage("HitKey",keyNumber)}

And then on the gate do a similar send message to say ("HitGate",gateNumber, gameObject)

And then on the player script you've got 2 functions called HitKey and HitGate

function HitKey(number){ keyNumber = number; }

function HitGate(number, GameObj){ if(number == keyNumber){ Destroy(GameObj); } }

Comment
Add comment · Show 2 · 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 spinaljack · May 03, 2010 at 12:05 PM 0
Share

this way you can have a set of keys for different gates on the player

avatar image TerryN · May 03, 2010 at 02:27 PM 0
Share

You were right, my main problem was that I hadn't got the script on my player, great idea about the numbers for multiple gates. Thanks a lot :)

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

No one has followed this question yet.

Related Questions

Problem with collisions and Destroy(gameObject). 2 Answers

Make an object destroy the object it is touching? 2 Answers

Destroy object if collision is strong enouf 1 Answer

If two of the same objects spawn on top of each other, is it possible to destroy only one? 0 Answers

Press E in front of Object to Delete another Object? 0 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