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 Alex Vaghin · Jul 23, 2012 at 07:15 PM · animationposition

How to change animation in the code?

I have a dancing charachter created in 3d MAx and imported in Unity. There is a plane attached to his head to skin him with the hat. Some of the hats are a bit bigger - so I want to change the scale of this plane for some of them. I can do it in the visual editor runtime but when I do it with the code - nothing happens! I even wrote something like this

 void LateUpdate()
  {     
  m_kHat.renderer.transform.localPosition.Set(10.04f,1f,0.0f); 
  Debug.Log("m_kHat.renderer.transform.localPosition.x " + m_kHat.renderer.transform.localPosition.x);
  } 

What I see in the log is m_kHat.renderer.transform.localPosition.x 0.01794739

So it obviously does not change the pos. What do I do wrong?

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 stingman · Jul 23, 2012 at 07:45 PM

First off your code is accessing the position of the plane not the scale. You would need to use localScale if you wanted to scale the plane. The best way I can describe doing this is to write down the scale of each plane with each different hat. Then write code to display the appropriate scale depending on which hat is being displayed. Also, if the character can change hats at runtime then using late update is fine as long as you close the call and reset at a later point. Otherwise do this in the Start function to save on memory.

I would also declare variables for each hat with their scale dimensions:

for example:

     public GameObject hat; // a plane with the hat texture applied
     private float hatScalex = "whatever x value it has"; // adjusts the x value of the scale
     
     void Start() {
     if (hat != null)
     hat.transform.localScale.x = hatScalex;
 
 //another alternative would be to just declare the total scale in the Start function like so:
 
 hat.transform.localScale += Vector3("your x, y and z values would go here");
     }

This is just something to get you started. If you actually did want to edit the position and not the scale then just change localScale to localPosition. Hope this helps clarify a bit

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 Alex Vaghin · Jul 24, 2012 at 02:37 AM 0
Share

Thanks for the answer! It can be the solution. Finally I found the reason of this weird behaviour. The main problem there was that when I write

m_kHat.renderer.transform.localScale.Set(1.18f,1.1f,1.0f);

it does not change the scale, probably because localScale returns a copy of the actual scale object. If I write the following - it works

m_kHat.renderer.transform.localScale = new Vector3(1.18f,1.1f,1.0f);

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

set child object position when playing the animation 0 Answers

Syncing object's coordinate position with object's animation position. 3 Answers

unity game 1 Answer

What is causing my attack animation to be in a different position from my idle/run animation? 0 Answers

changing a specific keyframe value 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