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 Victor Fabiano · Dec 10, 2012 at 04:06 AM · c#objectscale

How do i set a "object.max" scale ex.:: X axis ?

I'm having some problems with object scale ...

Comment
Add comment · Show 1
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 rhys_vdw · Dec 10, 2012 at 05:53 AM 0
Share

Are you asking how to set the horizontal size of an object in world units? Or would you like to scale it by a factor?

ie. Do you want to say "this object should be five units wide" or "this object should be stretched to double its original width"?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by clunk47 · Dec 10, 2012 at 05:40 AM

You need to be specific. What language are you programming with? Here's an example in C#. Just attach this to any game object. Use the up and down arrows on your keyboard to control at runtime.

 using UnityEngine;
 using System.Collections;
 
 public class scaleTest : MonoBehaviour 
 {
     Vector3 scale;
     float speed = 5.0f;
     float max_X = 5.0f;
     float min_X = -0.5f;
 
     void Start()
     {
      scale = transform.localScale;
      max_X = transform.localScale.x + max_X;
      min_X = transform.localScale.x + min_X;
     }
 
     void Update()
     {
         transform.localScale = scale;
         if(Input.GetKey(KeyCode.UpArrow))
             scale.x+= speed * Time.smoothDeltaTime;
         else if(Input.GetKey(KeyCode.DownArrow))
             scale.x-= speed * Time.smoothDeltaTime;
         if(scale.x >= max_X)
             scale.x = max_X;
         if(scale.x <= min_X)
             scale.x = min_X;
     }
 }
Comment
Add comment · Show 6 · 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 rhys_vdw · Dec 10, 2012 at 05:51 AM 1
Share

This wont work... When you assign

 scale = transform.localScale;

you are creating a copy of the current Vector3 scale representation. You are then modifying that in code. Also this code sample doesn't change the "max" value of the x-axis of the scale (whatever that means).

avatar image clunk47 · Dec 10, 2012 at 06:15 AM 1
Share

Yes, it will work. I did miss the $$anonymous$$AX part but will edit. This changes the scale on the x axis. Try it before you say it doesn't work.

avatar image clunk47 · Dec 10, 2012 at 06:18 AM 1
Share

I have added the $$anonymous$$ and max floats to the script, sorry I missed that last time.

avatar image rhys_vdw · Dec 10, 2012 at 06:19 AM 1
Share

$$anonymous$$y apologies, I missed the line where you reapply the scale.

avatar image clunk47 · Dec 10, 2012 at 06:20 AM 1
Share

No worries Sir. Besides, I'm glad you pointed out that I missed the max part :D

Show more comments

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

11 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

Related Questions

Object scale 1 Answer

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Object's localScale 1 Answer

Picked up objects passes through objects 2 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