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 empath · Oct 06, 2013 at 02:03 AM · movement script

How do I make it so that when my player enters an area, a disabled script attached to my player becomes active?

Title asks all.

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 TrickyHandz · Oct 06, 2013 at 02:07 AM 0
Share

By area, do you mean within a trigger?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · Oct 06, 2013 at 02:25 AM

You must create a trigger volume and use the OnTriggerEnter event. For the trigger volume: create an empty object (menu Game Object/Create Empty) and add a box collider (menu Component/Physics/Box Collider), then adjust its dimensions, position, rotation etc. and set the Is Trigger check box. It's a good idea to identify the trigger by name or tag, so that only the right trigger does the desired effect - let's call it "Area1", for instance.
The OnTriggerEnter event is sent to both, the player and the trigger - the easiest solution in your case is to add the OnTriggerEnter function to the script you want to enable (this event occurs even in disabled scripts):

 function OnTriggerEnter(other: Collider){
   if (other.name == "Area1"){
     this.enabled = true; // enable the script
   }
 }

NOTE: For this to work, the player must be a CharacterController or Rigidbody, or the trigger must have a kinematic Rigidbody.

Comment
Add comment · Show 6 · 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 empath · Oct 06, 2013 at 02:56 AM 0
Share

Alright I'll try that out tomorrow and I'll get back and see if it worked, but I need to go to sleep before I die x.x, cheers!

avatar image empath · Oct 06, 2013 at 03:15 AM 0
Share

Ehhehehe... So the script I want to enable is C#, you wouldn't know what to write for a C# script would you?

Yes yes I realize I should've put that in the OP now >_>

avatar image TrickyHandz · Oct 06, 2013 at 03:16 AM 0
Share
 void OnTriggerEnter(Collider other)
 {
   if(other.name == "Area1")
   {
     this.enabled = true;
   }
 
 }
avatar image empath · Oct 06, 2013 at 03:30 AM 0
Share

Ahahamuhahaha! Brilliant simple success. Can I assume that this.enabled = false; will turn the script off if I set void OnTriggerExit(Collider other) at the top?

avatar image TrickyHandz · Oct 06, 2013 at 03:33 AM 0
Share

You are correct.

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

17 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

Related Questions

How to to Disable a Script with Character Enters Zone? (JS) 0 Answers

Moving a player with Rigidbody 2 Answers

Script disables for no reason 1 Answer

How to stop player movements while the player is falling? 0 Answers

How do I stop my player or camera from jittering during player movement? 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