Author Topic: [SOLVED] Widget still responds to events, even though its script is disabled!  (Read 1789 times)

vexe

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 153
    • View Profile
Hello, I have a script called TextFile, that I only want to enable once I pickup the text file game object, it has a lot of stuff that I must set AFTER I pick it up. Some of those stuff are accessed in events such as OnHover, so if I hover over the gameobject with the TextFile BEFORE picking it up I get en exception, things are not set yet. So all I should do, is disable the script at first, and when I pick it up (which is done from another FilePickupScript attached to the game object as well) I enable the TextFile and assign the missing stuff.

But the problem is, even though I disabled the TextFile script, its events still got triggered! (OnHover got called!)

What is going on? why is this happening?
« Last Edit: September 04, 2013, 04:43:21 AM by vexe »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Widget still responds to events, even though its script is disabled!
« Reply #1 on: September 04, 2013, 04:41:14 AM »
Intentional. Unity sends messages to all scripts, even disabled ones. Do a simple "if (!enabled) return;" at the top of your OnHover function.

vexe

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 153
    • View Profile
Re: Widget still responds to events, even though its script is disabled!
« Reply #2 on: September 04, 2013, 04:42:54 AM »
EVIL Unity, good Aren, happy me ^_^