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 /
avatar image
0
Question by JustinProo · Mar 28, 2020 at 05:37 PM · animatorlerp

How can i check if an animation is done?,How to check if an animation is done?

I am using an animator with the only layer being one animation that only plays once and doesnt loop, as soon as the animation is done i would like the player2 to be sucked up into the space ship, i tried searching it but none of those answers worked so thats why im asking here. This is my code, but only look at the alien part since i havent worked on the astronaut yet.

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class FirstToEnd : MonoBehaviour { [Header("Alien")] [SerializeField] GameObject AlienShip; [SerializeField] Vector2 AlienShipStart; [SerializeField] Vector3 AlienShipEnd; [SerializeField] GameObject Player2; bool AlienShipLerp = false; bool Player2Lerp = false; [SerializeField] Vector3 Offset = new Vector3(0, 200);

 [Header("Astronaut")]
 [SerializeField] GameObject AstronautBuilding;
 [SerializeField] GameObject Tubes;
 [SerializeField] GameObject Player1;

 [Header("Lerp")]
 [SerializeField] float TimeStartedLerping;
 [SerializeField] float LerpTime;
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.transform.CompareTag("P1"))
     {
         GetTubes();
     }
     else if (collision.transform.CompareTag("P2"))
     {
         GetUfo();
     }
     GetComponent<BoxCollider2D>().enabled = false;
 }
 void GetTubes()
 {
     AstronautBuilding.SetActive(true);
     Tubes.SetActive(true);
 }
 void GetUfo()
 {
     AlienShip.SetActive(true);
     LerpUfo();
 }

 void LerpUfo()
 {
     TimeStartedLerping = Time.time;
     AlienShipStart = AlienShip.transform.position;
     AlienShipLerp = true;
     Player2.GetComponent<Player2>().enabled = false;
     Player2.GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezePosition;
 }
 private void Update()
 {
     if (AlienShipLerp)
     {
         AlienShipEnd = Player2.GetComponent<Transform>().position + Offset;
         AlienShip.transform.position = Lerp(AlienShipStart, AlienShipEnd, TimeStartedLerping, LerpTime);
         if (AlienShip.transform.position == AlienShipEnd)
         {
             AlienShip.GetComponent<Animator>().enabled = true;
             if (!AlienShip.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName("UfoAnimation"))
             {
                 Invoke("UpPlayer", 0.01f);
                 TimeStartedLerping = Time.time;
                 AlienShipLerp = false;
             }
         }
     }

     if (Player2Lerp)
     {
         Player2.transform.position = Lerp(Player2.transform.position, Player2.transform.position + Offset, TimeStartedLerping, LerpTime);

         if (Player2.transform.position == Player2.transform.position + Offset)
         {
             Player2.SetActive(false);

             Player2Lerp = false;
         }
     }
 }
 Vector3 Lerp(Vector3 start, Vector3 end, float timestartedLerping, float lerpTime = 1)
 {
     float timeSinceStarted = Time.time - timestartedLerping;
     float percentageComplete = timeSinceStarted / lerpTime;

     var result = Vector3.Lerp(start, end, percentageComplete);

     return result;
 }

}

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

0 Replies

· Add your reply
  • Sort: 

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

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

2D Animation does not start 1 Answer

Transform.Rotate keeps snapping back to original position after it has finished 0 Answers

What is the proper way to organize animator transitions to a large amount of abilities? 0 Answers

[4.6 UI] Image fading - How to? 2 Answers

Waiting for condition to be true for X amount of time before allowing transition in animator? 0 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