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 SirWaffleGamin · Feb 08, 2016 at 05:21 PM · c#animationscripting problemtriggers

How to have a trigger activate animation on another game object.

In order to be able to accurate explain my problem, I will use an analogy.

If you have played Portal 2, you know that if you place a cube on a button, something will activate, say open a door. I want to have a similar mechanic. I know the button will be a trigger object and it will check, but how to connect the button being triggered to the door opening via C# scripts is what I don't know how to do.

I guess in short, activating another object through the script of another unrelated object (assume the two aren't colliding or near each other) is what I'm having trouble with.

Thanks! Let me know if you need ore information.

Thanks!

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
2
Best Answer

Answer by Guhanesh · Feb 12, 2016 at 10:54 AM

 using UnityEngine;
 using System.Collections;
 public class TriggerScript: MonoBehaviour {
 public Animation anim;
 void OnTriggerEnter() {
 ani.enabled = true;
  }

Add this script to Trigger Object.Add Animation component of Door to anim in Inspector Disable Animation component on Door GameObject. or watch this https://www.youtube.com/watch?v=vL7CIvWxq4w

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 SirWaffleGamin · May 03, 2016 at 06:07 PM 0
Share

It's been a long time but I have another question for you. How would I play the same animation, but in reverse when the object triggering the script is no longer in contact with the trigger.

Say if this script was to be applied to the Portal 2 box and button mechanic I used earlier. I have it to where a door would open when the box comes into contact with the button, but I don't know how to close the door when the box is no longer in contact with the button.

avatar image
0

Answer by hexagonius · Feb 08, 2016 at 09:25 PM

The easiest way would be to have one script on the trigger and one script on the door. the script on the trigger should have a public variable of type door script. In the inspector you should then be able to drag the door onto the variable of the trigger now visible in the inspector. The whole gameobject suffices, the script will be picked automatically instead. now you should be able to call upon public methods in the trigger script on the door script variable.

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 SirWaffleGamin · Feb 10, 2016 at 06:25 PM 0
Share

Thanks. Could you give me an example with code? I'm not very experienced with C#.

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

Click on object and play animation\sound C# script 1 Answer

Play Animation OnTriggerEnter2D 1 Answer

Help with OnTriggerEnter Not working correctly? 1 Answer

Trigger animator in script (Unity 5/ C#) 1 Answer

Animation rigging doesnt work until I disable and re-enable Rig Builder 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