Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

how to reduce the object

Discussion in 'Scripting' started by palboy, Apr 6, 2014.

  1. palboy

    palboy

    Joined:
    Apr 6, 2014
    Posts:
    5
    Hi guys! During creation my script i have some problems with reducing the object

    when i create new Vector 3 transform
    Code (csharp):
    1.  
    2. transform.localScale += new Vector3 (Time.deltaTime * 0.7f, Time.deltaTime * 0.7f, Time.deltaTime * 0.7f);
    3.  
    and when this new Vector3 reach transform in 2 unit

    Code (csharp):
    1.  
    2. if (transform.localScale.x >= 2.0f) {
    3.       ...
    4. }
    5.  
    I cant start to reduce this Vector3(((
    I tried transform.localScale -= transform.localScale; transform.localScale -= Vector3.one * 0.7f; but no result(((
    help me please!:cry:
     
    Last edited: Apr 6, 2014
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    You could try using Tweens. I use HOTween. But there are plenty. I use it for all toes of scaling, movement and rotations. Handy easy, etc.
     
  3. palboy

    palboy

    Joined:
    Apr 6, 2014
    Posts:
    5
    What is that - "Tweens"?
    Do u mean, that i can't do this without this program?
     
  4. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    Well your code perplexes me. If your code works to increase the size, it should to decrease.

    Tweens are plug ins that allow manipulation of transforms.
    You don't need tweens. They just help in making animations (from scale, or position etc) sexy.
     
  5. palboy

    palboy

    Joined:
    Apr 6, 2014
    Posts:
    5
    Yeah, my code increase size of my object, but when this object reach size of 2.0 unit, i dont know how i can reduce this size((
    I said that i tried some variants, but it doesnt work((
     
  6. damian.doroba

    damian.doroba

    Joined:
    Apr 4, 2013
    Posts:
    36
    The simpliest (no-using external scripts) way is something like this:

    Code (csharp):
    1.  
    2.  
    3. public Vector3 velocity = Vector3.zero;
    4.  
    5. public void Update()
    6. {
    7.     transform.localScale += velocity*Time.deltaTime;
    8.     if(transform.localScale.x >= 2.0f || transform.localScale <= 1.0f)
    9.         velocity *= -1.0f;
    10. }
    11.  
    12. public void StartAnimation()
    13. {
    14.     velocity = Vector3.one;  // use this to setup animation
    15. }
    16.  
    17.  
    Of course it is only little snippet and you have to change it for your purposes
     
  7. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    -= the opposite of +=
     
  8. palboy

    palboy

    Joined:
    Apr 6, 2014
    Posts:
    5
    this code doesnt work(((
    the object dont increased in size and do not reduced

    :cry: why its so difficult
     
  9. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Did you call the StartAnimation function in that code?
     
  10. palboy

    palboy

    Joined:
    Apr 6, 2014
    Posts:
    5
    Yeah, but nothing happens