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 Digital-Phantom · Jan 14, 2015 at 02:00 PM · vector3scalevaluelocalscalereduce

How to stop scale reducing from reaching Zero (Solved)

Im using a very simple script to make an object get smaller over time

 #pragma strict
 
 function Update()
 {
     transform.localScale -= Vector3(0.002,0.002,0.002); // Reduce object size by .002 per frame
 }

Now think of it like iron ore being mined, eventually the object will reach scale 0 once its all been mined. It's at this point I want the reduce scaling to stop. (at the moment it goes into negative figures and grows again)

How can I set the object(objects scale) a value or percentage? I don't want it to reach less than zero, better still be able to stop it at about 2% of the original size.

Do I have to assine an INT/Float value to each of the vector3 x,y,z co-ordinates (and if so... how?)

Or is there a more efficient way to do this?

The script so far now is-

 #pragma strict
 
 var beingMined : boolean = false;
 
 function Update()
 {
     if(beingMined == true)
     {
         transform.localScale -= Vector3(0.002,0.002,0.002); // Reduce object size by .002 per frame
     }
 }


As usual any help/suggestions is greatly appreciated.

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 Scribe · Jan 14, 2015 at 02:30 PM 1
Share

you could do:

 transform.localScale -= Vector3(0.002,0.002,0.002);
 transform.localScale = Vector3.$$anonymous$$ax(Vector3(0.02, 0.02, 0.02), transform.localScale);

1 Reply

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

Answer by HarshadK · Jan 14, 2015 at 02:07 PM

One possible way is to do this:

 #pragma strict
   
   var beingMined : boolean = false;
   
   function Update()
   {
       if(beingMined == true)
       {
          // Check if the local scale of the object is greater than zero on all axes. And if yes, then only decrement
          if(transform.localScale.x > 0 && transform.localScale.y > 0 && transform.localScale.z > 0 )
          {
              transform.localScale -= Vector3(0.002,0.002,0.002); // Reduce object size by .002 per frame
          }    
          
          // This check makes sure that the scale does not reach below zero
          if(transform.localScale.x < 0 && transform.localScale.y < 0 && transform.localScale.z < 0 )
          {
              transform.localScale = Vector3.zero; 
          }  
          
       }
   }

Comment
Add comment · Show 2 · 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 Digital-Phantom · Jan 14, 2015 at 02:32 PM 0
Share

Certainly looks better than my attempt -

 #pragma strict
 
 var being$$anonymous$$ined : boolean = true;
 var oreAmount : int = 1;
 
 function start()
 {
     //transform.localScale = Vector3(oreAmount,oreAmount,oreAmount);
 }
 
 function Update()
 {
     
     transform.localScale = Vector3(oreAmount,oreAmount,oreAmount);
     
     if(being$$anonymous$$ined == true && oreAmount >= 0)
     {
         transform.localScale -= Vector3(0.002,0.002,0.002); // Reduce object size by .002 per frame
     }
     
     else
     
     {
         being$$anonymous$$ined = false;
     }
 }
 

Tried putting my first statement in the Start function but that didn't do anything (its commented out now).

Tried again with a comment in the function update and the damn ore turned into some kind of giant 1000 times larger and crashed unity...lol. Would be interesting to know why/how it caused that effect ?

avatar image Digital-Phantom · Jan 14, 2015 at 02:41 PM 0
Share

You missed another && from your statement, but apart from that it works perfectly.

$$anonymous$$any thanks, much appreciated !

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

26 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

Related Questions

problem Changing Scales in Script -C# 4 Answers

Add a value to a string 1 Answer

Resize object forward instead of along the z axis 4 Answers

Scaling objects over time? 3 Answers

LocalScale not working idealy 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