• 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 Pedrocosta2111 · Oct 27, 2015 at 05:08 PM · c#animationstate

Change animation speed in randomly generated objects

Hi there.

I'm currently devoloping this little project and I was wondering how can I change the animation speed of several instances of a prefab.

Let me explain a little bit better.In this game the basic concept is that pieces appear in random positions of the screen and they can be from 4 possible types (red,green,blue,yellow) and i would like for when they spawn, each piece as its own animation speed(a random one,of course it can be repeated).

I dunno if I made myself clear but it's my first time posting here my questions.

Thank you for your time and have a nice day.

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
0

Answer by ARKMs · Oct 28, 2015 at 12:54 AM

If are you using animator, you can use:

 newGameObject.GetComponent<Animator>().speed = Random.Range(minSpeed, MaxSpeed);

Where speed, affect all speed animations in the Animator.

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 Pedrocosta2111 · Oct 30, 2015 at 01:51 PM 0
Share

From what I understood about your answer, it doesn't work, but let me know if i'm doing everything correctly.Here's my code:

 private GameObject p;
 p=Instantiate (bluePiece, new Vector3 (spawnX, spawnY, 8), Quaternion.Euler (0, 0, 0)) as GameObject;

So, what you're trying to tell me is that, in this case, I should do

 p.GetComponent().speed=Random.Range(x,y);

If so do you know why it doesn't recognize this as a valid command?

avatar image Ymrasu Pedrocosta2111 · Oct 30, 2015 at 02:18 PM 0
Share

AR$$anonymous$$$$anonymous$$s was using pseudo-code, you need to use GetComponent() to grab the animator:

 p.GetComponent<Animator>().speed
avatar image ARKMs Ymrasu · Oct 30, 2015 at 06:59 PM 0
Share

Yes, it was a bug when i paste my code :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.

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

32 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

Related Questions

Get what the animation is transitioning into. 0 Answers

Animation play not working C# 0 Answers

Does anyone have a good script that can be used to make a horse/vehicle rideable? 0 Answers

My double jump won't work i have this code from BlackThornProds video ,My Double Jump won't work 1 Answer

Unity is reseting Dictionary when game is playing 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