• 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 Martinius222 · Jan 17, 2019 at 09:14 PM · triggerscaling

Help with pickup animation (Scale object up, down and dissapear)

Hello guys! I recently took up Unity and C#. I'm building a simple game where I have a few capsules spread around the board. I've set them up to dissapear when hit by a sphere. This works, but it's very abrupt with just an other.GameObject.SetActive(false).

What I'd like them to do is having their scale "inflate" a little bit then "deflate" to a point where you don't see them anymore and then remove them from the game with a SetActive(false).

As you can see from my code I only made them to inflate (tough abruptly). Any idea for a simple code to create this animation?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PickUp_Anim : MonoBehaviour {
 
     public float speed;
 
     void OnTriggerEnter (Collider other)
     {
         if (other.gameObject.CompareTag("Pick Up"))
         {
             other.gameObject.transform.localScale += new Vector3(3, 5, 3) * (Time.deltaTime * speed);
             other.gameObject.SetActive(false);
         }
 
     }
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by cs120319992 · Jan 18, 2019 at 01:48 PM

Yes, use coroutine

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
  
 public class PickUp_Anim : MonoBehaviour {
  
     public float speed;
  
     private void OnTriggerEnter (Collider other)
     {
         if (other.gameObject.CompareTag("Pick Up"))
         {
             StartCoroutine(AniamteScale(other.collider.gameObject));
         }
     }
 
     private IEnumerator AnimateScale (GameObject obj) 
     {
          for(float time = 0; time < 1; time += Time.deltaTime * 5) 
          {
              obj.transform.localScale = Vector3.Lerp(obj.transform.localScale, Vector3.zero, time);
              yield return null;
          }
 
          other.gameObject.SetActive(false);
      }
 
  }
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 Martinius222 · Jan 22, 2019 at 01:39 AM 0
Share

Thanks man! Exactly what I was looking for! :D

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

119 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

Related Questions

Scaling Object but not attached Trigger 1 Answer

Triggers with resizing colliders -1 Answers

Can't click gameobject when over another trigger? 1 Answer

Shuttle Runs & Counter 0 Answers

Scaling through script C# 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