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 pickleleon · Feb 27, 2014 at 06:43 PM · animationcolliderseparateunity 4.3.4

Trigger animation using script on separate box collider

I'm trying to do something that I thought would be very simple, but it's proving to be very difficult to figure out.

I have a box collider with 'Is Trigger' enabled, and I want to add a script to this trigger box to play an animation on another game object. This game object has an animation on it, which was created in unity. I am using unity 4.3.4.

Example:

-Walk through underground tunnel where a collider box is entered.

-On entering the collider box a train animation is triggered

-Train drives down platform and stops (as animated)

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

Answer by pickleleon · Mar 06, 2014 at 10:11 PM

Thanks for your input, this worked for me. Just applied this script to the trigger box and dragged in the corresponding game objects.

 var  Train: GameObject; //object to be animated
 var TrainAnimation : String; //animation to be played
        
 function OnTriggerEnter(Collision){
 Train.animation.Play(TrainAnimation);
 } 

After this I was getting a message about marking the animation as legacy. To do this with a unity made animation I found out I had to follow these steps.

  1. Switch the Inspector panel to a debug mode (3 stripes in a right top corner, near lock icon)

  2. Set the animation type to a "1"

  3. Switch the Inspector panel to a normal mode

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
avatar image
0

Answer by Levocakes · Feb 27, 2014 at 08:41 PM

I haven't used animations before in unity yet but I think this will help you to get started.

So you have a Box that has a script. When you walk through that "Box" which is a trigger it will make the animation play. I think something like this will help you.

The Train Script:

 using UnityEngine;
 using System.Collections;
     public class TrainScript: MonoBehaviour {
     
         public bool PlayAnimation = false;
     
 
         void Start () {    
         
         }
         
 
         void Update () {
             if(PlayAnimation){
             // Whatever function or code you write to start the animation
             // or however you want to do the animation}
         }
         
         
     }

This Box Script :

 using UnityEngine;
 using System.Collections;
 
 public class Box: MonoBehaviour {
        // Make sure you have the Train Object
     public GameObject Train;
       // The Script of the train;
     private TrainScript trainscript;
 
      
     void Start () {    
                 // This will get the script and set the trainscript
         trainscript= Train.GetComponent("TrainScript ") as TrainScript ;
     }
     
     // Update is called once per frame
     void Update () {
         
     }
     
     void OnTriggerEnter(Collider collision){
         if(collision.gameObject.tag == "Your Character's Tag"){
             trainscript.PlayAnimation = true;
         }
     }
 }

Now what this should do is, when your mainplayer/character enters the Box/Trigger it will edit the bool inside the train's script to make it true. Then inside of the trainscript you will have a case if that bool is true it will make the animation run/play.

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 pickleleon · Mar 04, 2014 at 08:36 PM 0
Share

Is there a way of calling a component on a separate game object without putting scripts on both? And I wanted to know the script for playing an animation too (not sure if it's different on later versions of Unity).

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

21 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 avatar image avatar image avatar image avatar image

Related Questions

Play animation when in collider and button pressed 1 Answer

Gradually change distance fog over time with a collider object. 1 Answer

Animation Script not working. 1 Answer

animation and sound on collide 1 Answer

Creating a collider in a gameObject using only code 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