Search Unity

what is the best way to scale with script?

Discussion in 'Scripting' started by yurinkab, Feb 9, 2016.

  1. yurinkab

    yurinkab

    Joined:
    Dec 9, 2015
    Posts:
    7
    Hi!
    I couldn't find the right script to scale and object.
    what I want to achieve finally is an object that scale and than scales down when it reaches certain size.
    what would be the most simple way? (i'm new to scripting in Unity :)

    Thanks!
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  3. yurinkab

    yurinkab

    Joined:
    Dec 9, 2015
    Posts:
    7
    Ah Very god! thanks for the quick answer!
    But can you please help me with this code?
    I really don't have any clue...
    I want the object to scale to a certain level and then when lets say its X it will scale down than again.
    how do I do that?

    Thanks!
     
  4. illuminatigaming

    illuminatigaming

    Joined:
    Jan 16, 2016
    Posts:
    17
    Is there a transform.scale or something like that?
     
  5. yurinkab

    yurinkab

    Joined:
    Dec 9, 2015
    Posts:
    7
    I used the local scale that LeftyRighty proposed.
     
  6. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    there is only the localScale, as I said, the scales are dependant on things higher up in the hierarchy. So there isn't a "global" scale, unlike position and localPosition etc.

    Ok, to keep things simple lets work with Update to start with (coroutines would be a later topic if you're just starting).

    Code (pseudo):
    1.  
    2. // pseudocode
    3. bool growing = true // control direction
    4. float targetScale // X
    5. float scalingSpeed // control how fast
    6.  
    7.  
    8. //in update
    9. if(scale < targetScale && growing)
    10. {
    11.     scale += Time.deltaTime * scalingSpeed
    12. }
    13. else
    14. {
    15.     growing != growing;
    16. }
    17.  
    18. if(scale > startingScale && !growing)
    19. {
    20.     scale -= Time.deltaTime * scalingSpeed
    21. }
    22.  
    23.  
    that's a basic outline which should get you started, try to flesh that pseudocode out
     
unityunity