Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 staraffinity · May 20, 2016 at 01:45 PM · interfaceinteractionanimatefade out

Animation won't play when clicking button

I have an animation which I want to get played – it's a black ”curtain” image that's supposed to fade in from 0 alpha to 1 to make the scene dark, resulting in a ”fade out” scene effect.

The animation works fine when I play it manually in Unity, but when I attach the Panel (which has the animation) to a Button and adding a ”On Click” parameter, dragging the Panel in to the object box and then choosing ”Animator” > ”Play (string)” and naming the animation I want to play in the box underneath, doesn't cut it – the animation isn't played when I click ”Play” in unity and click the button that should trigger the animation.

I have checked through things and I can't find what's wrong. :( Any ideas?

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
1

Answer by FortisVenaliter · May 20, 2016 at 02:23 PM

If you're using an Animator, you ought to add an AnimatorController, and a trigger that will start the fade animation.

Then, on your button, rather than calling Play(string), call SetTrigger(string), and the AnimatorController will take care of the rest.

If you're using an Animation instead of an Animator, then what you outlined should be correct, so you must have missed a step in the execution. Post screenshots of the inspector settings for those things so we can take a look.

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 staraffinity · May 20, 2016 at 06:52 PM 0
Share

Thanks so much for your reply! :)

I'm not sure, but it seems to me I'm using both an Animator and an Animation- :-| At least I have a tab called ”Animator” and a tab called ”Animation” in Unity and both contains stuff. :) As you can tell I'm pretty new to all this still…

Anyway, I'm attaching three screenshots – one of the inspector for the ”panel” (the black canvas) and one of the inspector for the button (the one I want to trigger the animation when being clicked on). Also a third screenshot with the Animation and the Animator tabs visible.

I tried to change the ”Play(string”) to ”SetTrigger(string)” but no go. I guess there's something more missing…

Had some trouble attaching the screenshots here, so here are links to them on my Dropbox:

Inspector view when Panel (black canvas) selected: https://dl.dropboxusercontent.com/u/2096906/Pictures/Unity/Panel-Black_Curtain.png

Inspector view when button is selected: https://dl.dropboxusercontent.com/u/2096906/Pictures/Unity/Button.png

View of entire Unity window with Animator and Animation tabs visible: https://dl.dropboxusercontent.com/u/2096906/Pictures/Unity/Animator_and_animation.png

avatar image FortisVenaliter staraffinity · May 23, 2016 at 09:05 PM 0
Share

You should not be using both. And don't look at the tabs, look at the components attached to the GameObject.

I recommend you pick one, and watch some tutorials to fully understand how it works before proceeding.

avatar image staraffinity FortisVenaliter · May 23, 2016 at 10:15 PM 0
Share

Uhm, okay.

What I've done is to follow the guide here: http://www.thegamecontriver.com/2014/09/add-fade-between-scenes-unity-46.html

I just did it again the other day – followed that guide in a new project and there both the fade in and fade out works fine. So there is something I have done different in my ”real” project.

Anyway, I'll try to look at some tutorials as you suggested and see if I can get my head around things.

Thanks again!

avatar image
0

Answer by staraffinity · Jun 04, 2016 at 11:43 PM

Seems I've found the problem.

In the Hierarchy tab I had the button placed as a child to the black image curtain that's animated to fade in and out. When the button was placed there the animation wasn't triggered, but as soon as I moved out the button so it's next to the curtain game object (so to speak) the animation (and scene switching) works fine when clicking the button!

Not sure if this is the intended behaviour in Unity or if it would be considered a bug.

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 Yashdss · Mar 23, 2021 at 07:40 AM 0
Share

bro i have a problem when i click right mouse button my animation does not work but however the bool gets checked. here is the code using System.Collections; using System.Collections.Generic; using UnityEngine;

public class FiringPistol : MonoBehaviour { public bool isAi$$anonymous$$g = false; public GameObject thePlayer;

 void Update()
 {
     if (Input.GetMouseButton(1))
     {
         isAi$$anonymous$$g = true;
         thePlayer.GetComponent<Animation>().Play("Pistol");
     }
     else
     {
         isAi$$anonymous$$g = false;
         //thePlayer.GetComponent<Animation>().Play("Idle");
     }
 }

}

Please help me bro

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

55 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 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 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

Forcing interaction with a gameobject 1 Answer

Set a Toggle active in ToggleGroup via script 2 Answers

LayoutRebuilder Does not fully rebuild complex parented layout groups 1 Answer

How to change/fix Shader Graph node connection ports 3 Answers

interact objects images or canvas 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