Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Dragonfly3r · Oct 23, 2014 at 03:18 PM · collisiondetectioninvisiblevisible

Make invisible wall appear visible upon collision/detection

SO I've managed to make a script in which when a visible wall collides with the player's bullet it will disable the renderer & collider for 6 seconds before reappearing. Now I want to make a secondary script which makes invisible walls with their colliders & renderers disabled and upon collision/detection of a bullet passing through, it enables both renderers & colliders for a specific set of time or until the player shoots the wall again to make it disappear.

The code for making the wall invisible is shown here:

 function OnTriggerEnter(col : Collider) {
  if (col.tag == "Bullet") { //If it is the bullet entering the collider
  renderer.enabled = false;
  collider.enabled = false;
  Invoke ("ReEnable",5); //Re-enable it in 10 seconds
  }
  }
  function ReEnable() {
  renderer.enabled = true;
  collider.enabled = true;
  }

The main problem I've been encountering is that when the collider is disabled firstly when a bullet is shot pass it won't detect the collision to enable the collider & renderer as the collider isn't turned on in the first place.

Any ideas?

Comment
Add comment · Show 1
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 robertbu · Oct 23, 2014 at 03:19 PM 0
Share

Never tried it dynamically, but can't you just set the 'isTrigger' flag rather than disable the collider?

http://docs.unity3d.com/ScriptReference/Collider-isTrigger.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by richyrich · Oct 23, 2014 at 04:18 PM

How about this...

     function OnTriggerEnter(col : Collider)
     {
         if (col.tag == "Bullet")
         { 
             //If it is the bullet entering the collider
             if (!isOnCountdown)
             {
                 renderer.enabled = false;
                 isOnCountdown = true;
                 Invoke("ReEnable", 5); //Re-enable it in 10 seconds
             }
             else
             {
                 renderer.enabled = true;
             }
         }
     }
 
     function ReEnable()
     {
         renderer.enabled = true;
         isOnCountdown = false;
     }



isCountDown is a bool declared at the top of the script

Comment
Add comment · Show 5 · 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 Dragonfly3r · Oct 24, 2014 at 12:13 AM 0
Share

Only problem I have with this is strangely enough the declaring of the bool :-D each time I declare it above function OnTriggerEnter as Boolean isOnCountdown; I get errors stating to add a semi-colon on the end when already is 1...

avatar image richyrich · Oct 24, 2014 at 12:53 AM 1
Share

It should be

 var isOnCountdown : boolean = false;

If you were to use c#, it would just be

 bool isOnCountdown = false;

I appreciate you don't technically need the '= false part' in this case, but I find it easier to initialise all variables whatever they are to avoid nasty surprises later on.

avatar image Dragonfly3r · Oct 24, 2014 at 02:16 PM 0
Share

ah, I see ta chap :-)

avatar image Dragonfly3r · Oct 24, 2014 at 02:22 PM 0
Share

Code works fine, only bug I've found is that when the player shoots bullet at it first time it does nothing, only on 2nd time bullet has been fired at it does it activate and also the collider doesn't enable itself to stop the player walking through it.

avatar image richyrich · Oct 24, 2014 at 03:00 PM 0
Share

Code works fine, only bug I've found is that when the player shoots bullet at it first time it does nothing, only on 2nd time bullet has been fired at it does it activate and also the collider doesn't enable itself to stop the player walking through it.

The collider should never be disabled in the first place. When the program starts, the collider should be enabled and stay that way for the duration of the game, unless you have some other feature you are implementing which interferes.

As for the player walking through, your trigger collider is not designed for that purpose. If you want that behaviour, you could just put another collider in the same location (but don't tick isTrigger) and set it as enabled or not depending on whether the renderer is enabled or not.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

collision wont work 1 Answer

Collision not working 3 Answers

Detecting Trigger Collision for Mecanim Animator 0 Answers

Collision detection not working properly with 2D sprites 1 Answer

Spawning and health script not working with collider? 1 Answer


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