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
1
Question by $$anonymous$$ · Apr 25, 2014 at 02:02 AM · gameobjectfindenabled

How to enable or disable a script OnTriggerEnter?

Ok, so I have been searching all over for help and right when I think I find a solution, I encounter a problem. I haven't scripted in a bit, so I am a bit rusty. Anyways, I want to enable a script of a different GameObject (in this case, one on the Main Camera in the FPS player prefab) and I can't seem to get it. Any time I try to use ".enabled" I get a syntax error. I have done this before, but cannot remember how. Here is what I have: #pragma strict

 function Start ()
 {
     var Blur : GameObject.Find("First Person Controller");
     Blur.GetComponent("Indie Effects").enabled = false;
 }
 
 function OnTriggerEnter (col : Collider)
 {
     if (col.tag == "Player")
     {
         Blur.active = true;
     }
 }
 
 function OnTriggerExit ()
 {
     Blur.active = true;
 }
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 getyour411 · Apr 25, 2014 at 02:15 AM 0
Share

A refresher...

http://answers.unity3d.com/questions/39748/disable-script-from-code.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Tony_T · Apr 25, 2014 at 09:49 AM

Try this:

 var Blur: GameObject; //The game object that has the script


 Blur.GetComponent.<ScriptName>().enabled = false;
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 $$anonymous$$ · Apr 25, 2014 at 02:46 PM 0
Share

I'll give it a shot, thanks.

avatar image $$anonymous$$ · Apr 25, 2014 at 11:47 PM 0
Share

Nope. Didn't work. Now the error gotten is BCE0019: 'IndieEffects' is not a member of 'function(System.Type): UnityEngine.Component'. Here is the script as updated: #pragma strict

 var Blur : GameObject;
 
 function Start ()
 {
     Blur.GetComponent.IndieEffects().enabled = false;
 }
      
 function OnTriggerEnter (col : Collider)
 {
     if (col.tag == "Player")
     {
         Blur.GetComponent.IndieEffects().enabled = true;
     }
 }
      
 function OnTriggerExit ()
 {
     Blur.GetComponent.IndieEffects().enabled = false;
 }
avatar image Tony_T · Apr 26, 2014 at 12:00 AM 0
Share

You missed the ""... it should look like this:

     Blur.GetComponent.<IndieEffects>().enabled = false;

If it still doesn't work, place the indie effect script in the standard assets but only if it's in C#.

avatar image $$anonymous$$ · Apr 26, 2014 at 12:20 AM 0
Share

Ok. Ill try that.

Edit: Nope. It works, no compiler errors, but now the error is "NullReferenceException: Object reference not set to an instance of an object Underwater.Start () (at Assets/Scripts/Underwater.js:7)" Here is the updated script with out the compiler errors:

 #pragma strict
 
 var Blur : GameObject;
 
 function Start ()
 {
     Blur.GetComponent.<IndieEffects>().enabled = false;
 }
      
 function OnTriggerEnter (col : Collider)
 {
     if (col.tag == "Player")
     {
         Blur.GetComponent.<IndieEffects>().enabled = true;
     }
 }
      
 function OnTriggerExit ()
 {
     Blur.GetComponent.<IndieEffects>().enabled = false;
 }
avatar image getyour411 · Apr 26, 2014 at 12:47 AM 0
Share

In the inspector look at the gameobject this script is attached to, there will be a field called Blur - have you drag/dropped the target gameobject into that?

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

20 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Can I limit a .Find to the Parents and Child and not the Scene? 3 Answers

Finding objects - same name - different atributes 3 Answers

Detect when instance has deleted 0 Answers

Typecasting problem? 3 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