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 mantisghost · Aug 18, 2012 at 07:55 PM · animationtriggerobjectcall

call/trigger animation of other object

Hello I have such objects in the scene: collider (that acts as trigger), elevator, animated button. Now when I enter the collider area and press f button and then get into elevator it goes up. I want make it so that when i enter the collider area and press f button the animation of other object named animated button will play too. I have such code for now.

Trigger script:

 static var leverswitch: int;
 var trigger: int=1;
 var Player: Transform;
 var AnimationFile: AnimationClip;
  
 function OnTriggerStay (other: Collider)
 {
    if (Input.GetKeyDown("f"))
    {
       leverswitch =trigger;
       Player.parent =null;
       animation.Play("AnimationFile");
    }
 }


Elevator script:

 var Player: Transform;
 var Elevator: Transform;
 
 var point1: Vector3; 
 var point2: Vector3; 
 var speed: int=5; 
 var boolswitch: lever; 
 
 function OnTriggerStay(other: Collider) {
 boolswitch=FindObjectOfType (lever);
 
 if (boolswitch.leverswitch==1) {
     if (Elevator.transform.position.y < point2.y) {
         Player.parent=Elevator;
         Elevator.transform.Translate(Vector3.up*Time.deltaTime*speed);
         }
     }
 }

This does not work as I get error: MissingComponentException: There is no 'Animation' attached to the "aktywator_windy" game object, but a script is trying to access it.

Can someone tell me how to fix it (make it work)?

Maybe this ugly picture will help it understand better: alt text

simplify.png (243.5 kB)
Comment
Add comment · Show 5
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 termway · Aug 20, 2012 at 04:52 PM 0
Share

Here "animation" variable seems null.

 animation.Play("AnimationFile");

Is the object attach to this script has an animation ? Enabled ?

The "AnimationFile" variable is also unused. $$anonymous$$aybe you forget something ?

 var AnimationFile: AnimationClip;
avatar image mantisghost · Aug 20, 2012 at 05:02 PM 0
Share

"Is the object attach to this script has an animation ? Enabled ?" If you ask if button have animation then yes it has. And I think it is enabled as I dont know how to disable animation. Also button does not have any scripts at all the thing is I want to play its animation using mentioned trigger.

"Here "animation" variable seems null.

animation.Play("AnimationFile");

This "AnimationFile" is unused. $$anonymous$$aybe you forget something ?

var AnimationFile: AnimationClip;"

I am begginer in scripting but I think this is correct as it gives me nice paremeter in Inspector where I can choose any animation from project assets. If im wrong then correct me.

avatar image termway · Aug 20, 2012 at 05:15 PM 0
Share

Your script file need to be on the object with the animation. Or you have to use an other Animation variable.

You can click on the error and see the call stack. Something like this :

  Animation.Start () (at Assets/Animation.cs:8)


This will help you to find your problem.

avatar image mantisghost · Aug 20, 2012 at 05:16 PM 0
Share

I did try to click on that and read logs and sadly it gave me no idea or tips how to resolve that. Could you be so nice to tell me that other animation variable then?

avatar image termway · Aug 20, 2012 at 05:21 PM 0
Share

It give you the file and the line of your execution error. It's vital for debugging to know these information.

 var Animation: Anim; //Drag and drop in your editor the animation.
 function OnTriggerStay (other: Collider){
    //...
    Anim.Play();
 }

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Mander · Aug 20, 2012 at 05:18 PM

where is ur script attached? and where is ur animation.? in that script u r tryin to acces an animation in the object where the script is attached. so u might need to call the correct gameObject to play the animation. `gameObject.FindWithTag("player");` or u can make a variable `var animated : GameObject;` and add ur player in the inspector anyway u want will work.

but remember that the object must contain the animation component with its animation.

srry for the confusing bad english. xD

Comment
Add comment · Show 3 · 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 mantisghost · Aug 20, 2012 at 05:21 PM 0
Share

the scripts are attached to empty's with box colliders as triggers

animation is on imported object from blender. Yes i know i need to call correct gameObject but i have no idea how. I will try to remade it as you written.

Remade the code to this yet still it does not work

static var leverswitch: int; var trigger: int=1; var Player: Transform; var animated : GameObject;

function OnTriggerStay (other: Collider) { if (Input.Get$$anonymous$$eyDown("f")) { leverswitch =trigger; Player.parent =null; // niszczy dziedziczenie animation.Play("animated"); } }

As GameObject i did choose button (it has its animation) from assest

avatar image Mander · Aug 20, 2012 at 05:29 PM 0
Share

in any script u can find objects by name or tags like this

var objectAnim : GameObject;

this way u can assign it in the inspector. just drag the gameObject.

then use like this objectAnim.animation.Play("AnimationFile");

or u can find in the script

var objectAnim : GameObject;

objectAnim = gameObject.Find("gameObject");

and use it just like in the 1st example

avatar image mantisghost · Aug 20, 2012 at 05:39 PM 0
Share

Ok I do not get any errors now but still it wont animate i must do something wrong? Also i would vote you up for helping me but somehow i cant (no premission error) sorry

avatar image
0

Answer by mantisghost · Aug 20, 2012 at 06:45 PM

Ok problem solved thanks again the correct code goes like this for me

 static var leverswitch: int;
 var trigger: int=1;
 var Player: Transform;
 //var AnimationFile: AnimationClip;
 var animated : GameObject;
  
 function OnTriggerStay (other: Collider)
 {
    if (Input.GetKeyDown("f"))
    {
       leverswitch =trigger;
       Player.parent =null;
       animated.animation.Play("dzwignia");
    }
 }

Everything works fine now

Comment
Add comment · Show 3 · 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 Mander · Aug 20, 2012 at 07:19 PM 0
Share

upvote :)

avatar image mantisghost · Aug 20, 2012 at 09:09 PM 0
Share

the thing is I can not i get "You don't have permission to do this action. Please Login as another user"

avatar image Mander · Aug 20, 2012 at 09:32 PM 0
Share

i see u dont have enough karma i guess. thx anyways and happy coding :P

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

10 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

Related Questions

Animated Object Problem 1 Answer

Presure plate that triggers an animation 1 Answer

Retrigger animation after play through 0 Answers

object animation trigger 0 Answers

importing exporting Animation 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