• 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 DivideByZero · Mar 26, 2013 at 02:01 AM · animationcollider

Need help with some OnTrigger Scripting

I am currently working on a maze type game, and I have run into a problem that requires some scripting that I don't know how to do. My idea is that once the player has collided with the collider, a separate game object's animation is played in w$$anonymous$$ch it comes down and blocks the exit of the maze. I've done some OnTrigger scripting for stuff like teleporters before, but t$$anonymous$$s one has got me confused.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Auggie · Mar 26, 2013 at 03:55 AM

what if you try somet$$anonymous$$ng like t$$anonymous$$s:

make two separate scripts-

 //attach t$$anonymous$$s on the player gameObject
 
 function OnCollisionEnter ( collision : Collision ){
 
     collision.gameObject.SendMessage("PlayAnimation", SendMessageOptions.DontRequireReceiver);
 
 }

and make another for the object in the maze

 //attach t$$anonymous$$s to a maze object
 
 function PlayAnimation()
     {
         gameObject.animation.Play("ClosingDoorAnimation");
     }


you can have the PlayAnimation() function on all of your maze object and just change the animation name inside that function.

i hope t$$anonymous$$s helps...

Comment
Add comment · Show 1 · 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 DivideByZero · Mar 27, 2013 at 03:43 AM 0
Share

So I attached the first script to my character controller and 2nd to the collider that's supposed to trigger the animation of the door coming down, but nothing happened. I tried to mess around with the two scripts, but got no luck. Suggestions? Thanks!

avatar image
0

Answer by Chronos-L · Mar 27, 2013 at 04:09 AM

If you are looking for somet$$anonymous$$ng similar to a trap trigger:

 public class RemoteTrapTrigger : MonoBehaviour {
    public GameObject trap;
 
    void OnTriggerEnter( Collider other ) {
       if( other.gameObject.CompareTag("Player") ) {
          trap.animation.Play("Activate");
       }
    }
 }

Attach t$$anonymous$$s script to the trigger, assign the door/trap as the trap.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

Multiple Cars not working 1 Answer

Reloading Help 2 Answers

Trying to simply play this animation... Help please. 1 Answer

Animation Script Help 0 Answers

Player lives script help 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