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 /
avatar image
0
Question by Richarrd82 · Aug 22, 2016 at 06:19 PM · scripting problemmovementfunctionobjectsdisable

Referencing Objects and disabling Scripts on them instantly

Hey guys! I have a problem...

I have platforms in my game. I use object pooling to spawn them in front of the player. Now the platforms are moving and what i want is when player jumps the platform will stop moving, that way he can time it and when he feels like the platform is in good position he will jump and the platform will "wait" until he lands and then leaves.

I don't know how to reference the platform in front of the player in the script and then disable the script responsible for the movement.

What i tried to do is put a empty game object on the player and put a trigger on it. Then i placed it on the platform in front of the player. Since the platforms have the same distance between it would always touch the platform in front of him. After that i tried to use OnTriggerEnter Stay and Exit but none of them seem to work. OnTriggerExit worked the best but there was a little delay in disabling the script. I need it to be instant it would be awesome if it could respond to the MouseClick Input function that makes the player jump.

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 incorrect · Aug 22, 2016 at 06:19 PM 0
Share

Could you post your code please?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by NotEnoughLemons3D · Aug 22, 2016 at 07:22 PM

Though I am unsure, the reason your triggers are not responding may be due to the fact that it is a child of a gameObject using a CharacterController. Whatever the case --

There are many options to achieve what you are looking for:

OPTION 1: Check out Physics.Raycast: https://docs.unity3d.com/ScriptReference/Physics.Raycast.html

It will basically check an imaginary line from a starting point towards a direction and return an object. Then you can use the object to access the platform script .gameObject.GetComponent<"NAME OF PLATFORM SCRIPT">().enabled = false. Then simply re-enable the script through another raycast or whenever the play jumps.

OPTION 2: Put box colliders as triggers on each platform instead of the player. Have the trigger check if the collider is the player and enable/disable on OnTriggerEnter/OnTriggerExit

Option 3: Similar to raycast, you can use Physics.OverlapSphere: https://docs.unity3d.com/ScriptReference/Physics.OverlapSphere.html

This would essentially create your own "Trigger" in a sense.

Check out the complete Physics documentation https://docs.unity3d.com/ScriptReference/Physics.html for other ways to achieve your goal.

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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Disabling Script on many Objects one at a time. 1 Answer

How to Have Projectile Reset to Initial Position Relative to Parent 1 Answer

How to fix a walking animation that when its done your player position gets reset to its starting position. 1 Answer

Enemy AI Movement Decision Making 1 Answer

Movement script (ironically) is not moving. 2 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