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
0
Question by Ayato-Naoi · Sep 28, 2015 at 08:50 PM · script.disable

What is wrong with my script?

Hello, I am having some problems with the script below: #pragma strict var Player : GameObject; var Chair : GameObject; var Chair2 : GameObject; var Chair3 : GameObject; var Chair4 : GameObject; var Table : GameObject; var Table2 : GameObject; var Table3 : GameObject; var Table4 : GameObject; var Table5 : GameObject; var Blackhole : GameObject; var VortexStop : AudioClip; private var Vortex : Wormhole; private var ResetLevelScript : ResetLevel;

 function Start () 
 {
     Vortex = Player.GetComponent(Wormhole);
     Vortex = Chair.GetComponent(Wormhole);
     Vortex = Chair2.GetComponent(Wormhole);
     Vortex = Chair3.GetComponent(Wormhole);
     Vortex = Chair4.GetComponent(Wormhole);
     Vortex = Table.GetComponent(Wormhole);
     Vortex = Table2.GetComponent(Wormhole);
     Vortex = Table3.GetComponent(Wormhole);
     Vortex = Table4.GetComponent(Wormhole);
     Vortex = Table5.GetComponent(Wormhole);
     ResetLevelScript = Blackhole.GetComponent(ResetLevel);
 }
 
  function OnTriggerEnter (Trigger : Collider) 
  {
       if(Trigger.gameObject.tag == "Player") 
            Vortex.enabled = false;
            ResetLevelScript.enabled = false;
       GetComponent.<AudioSource>().clip = VortexStop;
       GetComponent.<AudioSource>().Play();
  }

The problem I am having is that I want to disable the same script for multiple objects, but when my player passes through the trigger, only one object (table 5) has the script disabled. Is there a different method to disabling the scripts in multiple objects rather than just one? Thank you for any help, Ayato Naoi.

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 Jinxology · Sep 28, 2015 at 09:48 PM

That's because Table5 is the last thing you assign to Vortex. You keep overwriting Vortex with every assignment until it ends on Table5.

I'm not sure which object you have assigned that script to, but you need to have it on each of your objects that you want to disable when player collides with it.

Small best practice criticism, it helps to have your variables start with lowercase letters to distinguish them as variables and not object types (ie. use vortex instead of Vortex).

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 Ayato-Naoi · Sep 28, 2015 at 10:09 PM 0
Share

I should have added more detail to the description, but I have the Wormhole Script on all of the variables listed other than the Blackhole. I have this script on a box collider object which is marked as the trigger. The effect I was hoping for was that of one where all of the Wormhole scripts are disabled as soon as the player passes through the trigger.

avatar image Jinxology Ayato-Naoi · Sep 28, 2015 at 10:53 PM 0
Share

Can you lay out the bigger picture for me, what is your game? Also, rather than setting .enabled=false, I would recommend setting .isTrigger = false

avatar image Jinxology Jinxology · Sep 28, 2015 at 10:55 PM 0
Share

For clarity, I'm having trouble visualizing your game... wormholes and blackholes coupled with tables and chairs?

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Identical Lines of Code Will Either Disable, or Wont Disable a Script. Need Help. 0 Answers

Disable an added script from First Person Character 0 Answers

Disable a script for a few seconds 2 Answers

How to enable and disable a script on an game object by pressing a keyboard button? 1 Answer

How to disable my buttons when i press and enable the other ones? 0 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