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 Justin 6 · May 09, 2011 at 10:33 AM · collisioncolliderobjectsdisablelights

Disabling objects from Collision detection

My problem has to do with lights.

I have a spotlight, and I would like the spotlight to be turned off when my character touches an object I have created.

The script I have is:

private var GotHit = false; var TargetLight : Light;

function OnControllerColliderHit(hit : ControllerColliderHit) {

if(hit.gameObject.tag == "Collide")
{
GotHit = true;
}

}

function Update () { if(GotHit) { TargetLight.enabled = false; }

}

For some reason, It doesn't work. I've checked my tags, and I've specified the object to be disabled.

Does anyone have a general script to be used on collision to disable another object?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by superpig · May 09, 2011 at 10:42 AM

Why are you splitting the logic across both functions? Why not just do:

function OnControllerColliderHit(hit: ControllerColliderHit) {
    if(hit.gameObject.tag == "Collide") TargetLight.enabled = false;
}

If you do it that way, then you're reducing the number of things that could be going wrong.

Once you have an implementation that is simple like this, you can start debugging it. The first thing you could try would be to add a Debug.Log command, like this:

function OnControllerColliderHit(hit: ControllerColliderHit) {
    Debug.Log("OnControllerColliderHit is executing!");
    if(hit.gameObject.tag == "Collide") TargetLight.enabled = false;
}

When you run that script, you should see the message "OnControllerColliderHit is executing!" whenever you collide with anything. If you do, then we know that the problem is with the way that you're responding to collisions; while if you don't, then we know that the problem is that you're not being informed about collisions at all. That will help us narrow down the source of the problem.

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 Justin 6 · May 12, 2011 at 12:57 PM 0
Share

"Then you can use $$anonymous$$onoDevelop (or just Debug.Log) to make sure firstly that OnControllerColliderHit is being called, and secondly that hit.gameObject.tag is what you think it is."

I need you to simplify your meaning please, I'm not sure what to do. The coding you gave was my first script, but it wasn't working so I had changed it to what is above. So it's not a scripting problem, but the order of functions that are called? I'm not sure.

avatar image superpig ♦♦ · May 12, 2011 at 01:55 PM 0
Share

Edited and clarified.

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

How to block collision between selected objects 0 Answers

Collision details 1 Answer

How to know when two specific object colide 1 Answer

How do I get the player and the object they touch both disappear/destroyed? 1 Answer

Collision in between 2 objects moving away from each other? 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