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

Question Vector3 properties

Discussion in 'Scripting' started by MrPuppyy, Sep 25, 2020.

  1. MrPuppyy

    MrPuppyy

    Joined:
    Nov 4, 2019
    Posts:
    40
    So I guess my script is adding .4 onto it to make the stat even again. Origional is (16, 20, 5) and it takes off (16, 20, 4) then it adds it back on the (0, 0, 1)
    But I want to be able to not add it back on, i want to be able to make it change back to (16, 20, 5) because the key will be used as multiple scaling. (as examples ^)

    Code (CSharp):
    1.     bool resized = false;
    2.  
    3.     void Update()
    4.     {
    5.         if (Input.GetKey("f") && resized == false)
    6.         {
    7.    
    8.             Vector3 CurrentScale = transform.localScale;
    9.             Vector3 newScale = CurrentScale + new Vector3(0, 0, -0.6f);
    10.             transform.localScale = newScale;
    11.             resized = true;
    12.         }
    13.         else if (Input.GetKey("g") && resized == true)
    14.         {
    15.             Vector3 CurrentScale = transform.localScale;
    16.             Vector3 newScale = CurrentScale + new Vector3(0, 0, 0.6f);
    17.             transform.localScale = newScale;
    18.             resized = false;
    19.       }  
    20.    }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,758
    Track your own separate integer variable (or float) that you control how far it moves each step, and how high and low it can go.

    Then produce the scale based on that variable and the original scale:

    - in Start(), make note of the original scale into
    originalScale


    - when it changes, produce a new scale:

    Code (csharp):
    1. Vector3 newScale = new Vector3( originalScale.x, originalScale.y, yourHeightTracker + originalScale.z);
     
  3. MrPuppyy

    MrPuppyy

    Joined:
    Nov 4, 2019
    Posts:
    40
    i'm not really sure what you mean. The original scale is just a cube set to 1, 1, 1.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,758
    Please don't make duplicate posts: this seems to be nearly identical to https://forum.unity.com/threads/scaling-overtime.976704/

    What EXACTLY are you trying to do? From my interpretation of your post above, my reply should suffice.

    Prove me wrong, or explain yourself better.
     
    Bunny83 likes this.
  5. MrPuppyy

    MrPuppyy

    Joined:
    Nov 4, 2019
    Posts:
    40
    that one is to make the scale like tik overtime to get to the new scale like
    if original scale of X was 10, and i wanted to hit it to X5 i would want it to move X1 every second till it reaches 5. (example^)
    But this one I need to make it so one I click g, instead of it adding 0.6 back on, it just resets to 1, 1, 1.
     
  6. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    I could help as well, but you didn't explain yourself any better.
    try to formulate clearly what is it that you're trying to achieve. yes it has to do with scaling, which is a banal thing to implement if explained properly, and yes you already got your answer most likely, now it's just a matter of translation back and forth.
     
    Bunny83 likes this.