Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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
0
Question by Albert-han · Jun 09, 2014 at 01:18 PM · colliderdisableenable

Disable Collider After two Second of Being Triggered and enable it again

Hi guys i need help making a collider disabled for two seconds when collided with the player and reenable it after 2 second.Everytime my Player collides with the collider it adds 1 score so i need a script to disable it for 2 seconds when collided with the player so that the player cant collide 2 times and get double score and then reenable again.Here's my current script but i keep getting an error.Thanks

 using UnityEngine;
 using System.Collections;
 
 public class ScorePoint : MonoBehaviour {
 
     void OnTriggerEnter(Collider collider) {
         if(collider.tag == "Player") 
             Score.AddPoint( 
         (Collider = false)
                 (WaitForSeconds (2)
         (Collider = true)
         }
     }
 
 
Comment
Add comment · Show 2
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 PouletFrit · Jun 09, 2014 at 02:28 PM 0
Share

Since your collider seems to be a trigger you could simply disable your collider component when the player hit the collider and then reenable it in a Coroutine.

avatar image Albert-han · Jun 09, 2014 at 02:34 PM 0
Share

I am sorry i am a newbie.How would i disable my collider component when the player hit the collider and then reenable it in a Coroutine. I dont really understand that but is this it

  void OnTriggerEnter(Collider collider) {
 if(collider.tag == "Player")
 Score.AddPoint( 

How do i coroutine it? Thanks

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Albert-han · Jun 10, 2014 at 01:36 AM

Thanks guys i finally have a working script awesome! Heres the final code and i think figured out where to put ; and ) stuff using UnityEngine; using System.Collections;

 public class Score2 : MonoBehaviour {
     
     IEnumerator OnTriggerEnter(Collider collider) {
         if(collider.tag == "Player") {
             Score.AddPoint();
             gameObject.collider.enabled = false;
             yield return new WaitForSeconds (2);
             gameObject.collider.enabled = true;
         }
     }
 }
Comment
Add comment · Show 1 · 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
1
Wiki

Answer by Kiwasi · Jun 10, 2014 at 12:23 AM

You have so many coding errors here. Try this for starters and you may start getting sensible errors. (C# code)

     using UnityEngine;
     using System.Collections;
      
     public class ScorePoint : MonoBehaviour {
     
         IEEnumerator OnTriggerEnter(Collider collider) {
            if(collider.tag == "Player") {
                Score.AddPoint();
                collider.enabled = false;
                yield return new WaitForSeconds (2);
                collider.enabled = true;
            }
         }
     }

Remember the basics. Every line should end in a ; or {. Every ( needs a ). Every { needs a }.

Parsing error basically means the compiler has no clue what you are talking about.

Comment
Add comment · Show 3 · 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 Albert-han · Jun 10, 2014 at 12:52 AM 0
Share

I got the ienumerator working but now i get flooded with error messages i dont understand and i stops my character from moving when it colides with the collider. Error message is CharacterController.$$anonymous$$ove called on inactive controller UnityEngine.CharacterController:$$anonymous$$ove(Vector 3) and i notice my character controller also disables when i touch the collider.

avatar image Albert-han · Jun 10, 2014 at 12:57 AM 0
Share

I think it has something to do with my character controller script movement.collisionFlags = controller.$$anonymous$$ove (current$$anonymous$$ovementOffset); because im using a 3d character controller for my 2d game with forward and backward disabled.

avatar image Kiwasi · Jun 10, 2014 at 01:01 AM 0
Share

So now we are disabling the collider on your player ins$$anonymous$$d of the ScorePoint

Change line 9 and 11 to

 gameObject.collider.enabled = ...

If it works I will update my answer

avatar image
0

Answer by screenname_taken · Jun 09, 2014 at 02:32 PM

If this is a direct copy paste from your script, you forgot to add a couple of ")"

Comment
Add comment · Show 3 · 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 Albert-han · Jun 09, 2014 at 02:55 PM 0
Share

exactly where am i missing ")"? because i am new and i dont know where to put those things

avatar image screenname_taken · Jun 09, 2014 at 05:30 PM 0
Share

Just start pairing them. each ( needs to have a ) and each { needs to have its }. What is the error that unity gives you? It tells you the line and column that the error is at. You should really just give the unity manual a read. It has everything you need to get started in there.

avatar image Albert-han · Jun 10, 2014 at 12:05 AM 0
Share

I get parsing error.

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

24 People are following this question.

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

Related Questions

Ragdoll help 1 Answer

How to disable collision detection while a UI Panel is enabled 2 Answers

How do I disable all rigidbodies and colliders in a scene in unity? 2 Answers

Why does Unity disable the Collider when I Destroy the Rigidbody? (2D) 1 Answer

How to change settings to a rigidbody when adding it to a gamobject? 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