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 /
  • Help Room /
avatar image
1
Question by daviddickball · Jan 17, 2016 at 11:07 AM · javascriptboxcollidercomponents

How to set a BoxCollider to a variable, and disable it?

I'm stuck on something which I thought would be simple. I need to disable the BoxCollider on my projectile when it hits something. I don't want to delete it straight away, because it has a particle trail which needs to finish, so I thought hiding the graphic and disabling the BoxCollider would do the trick.

This doesn't work, but I thought it would:

 private var collider : BoxCollider;
 
 function Start () {
       collider = GetComponent.<BoxCollider>();
 }
 
 function OnTriggerEnter(other: Collider) {
       collider.isActive(false);
 }

I get the error "Language feature not implemented: Ambiguous(BulletScript.collider, UnityEngine.Component.Collider) I definitely have a Box Collider on the object this script is on. Any ideas guys?

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 DigitalCyan · Jan 17, 2016 at 11:51 AM 0
Share

@daviddickball Try using .enabled = false; ins$$anonymous$$d of .isActive(false);

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by SneakySquid · Jan 17, 2016 at 11:29 AM

It seems like it is confusing the name "collider" with something else. I'd suggest changing the name. Also you should use enabled = false instead of isActive for a component.

 private var boxCollider : BoxCollider;
 
 function Start () {
     boxCollider = GetComponent.<BoxCollider>();
 }
 
 function OnTriggerEnter(other: Collider) {
     boxCollider.enabled = false;
 }
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 daviddickball · Jan 17, 2016 at 02:17 PM 0
Share

Thanks for the tip about using enabled = false, but your code above doesn't change anything. All you've done is change the variable name?

avatar image SneakySquid daviddickball · Jan 17, 2016 at 09:42 PM 0
Share

That's correct, but as I said, I think the name you've chosen is being confused by another class or component in Unity. I added your code to my own project and I got the same errors as you. When I changed the name, it was fine.

avatar image brunocoimbra SneakySquid · Jan 18, 2016 at 12:08 AM 0
Share

Yes, $$anonymous$$onoBehaviours already has some variables like "collider", "collider2d", "renderer" and other ones that used to have the same funcionality as the "transform" variable (picking the component faster than GetComponent.()", but they became deprecated, so you can't use then now. They still exist, but only to maintain compatibility with older projects.

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

41 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 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

Semicolon expected before end of line 0 Answers

Javascript Help 0 Answers

Trigger enabling component works in one statement but not another? 1 Answer

Can't find any Unityscript tutorials 3 Answers

UnityScript to C# Conversion 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