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 Redirect for Transformation

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

  1. MrPuppyy

    MrPuppyy

    Joined:
    Nov 4, 2019
    Posts:
    40
    I went to the unity Manual api and was looking for info on how to use transformation as a script, but it only showed as a property, how would i come about this?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,758
    I don't understand your question, I'm sorry.

    Any script that inherits from
    MonoBehavior
    can access the
    Transform
    on the underlying
    GameObject
    by using the
    transform
    property.
     
    PraetorBlue likes this.
  3. MrPuppyy

    MrPuppyy

    Joined:
    Nov 4, 2019
    Posts:
    40
    Thanks man, you've been a really big help recently.
    Would i need to do something like this?
    transform.translate?
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    To do something like what? What are you trying to accomplish?
     
  5. MrPuppyy

    MrPuppyy

    Joined:
    Nov 4, 2019
    Posts:
    40
    Let's say I spawn a cube and i put a script on it (void update because of i have a keybind set to it) to change Transform property -> scale to make it different scale when you click that key. I got the click key part
    if(Input.GetKey("d"))
    {
    the script i'm trying to figure out how to make to transform scale here
    }
    i was wondering if transform.translate (2, 2, 2) for instance would work
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    You can think of the Transform component on the object as the set of transformations that are applied to the object. There are three main transformations you can change:
    • Position
    • Rotation
    • Scale
    Translation is a change to the position of the object. I don't think that's what you want. It sounds like you want to scale the object. You do this by changing the localScale property on the Transform. For example, to double an object's size you might do something like this:

    Code (CSharp):
    1. Vector3 currentScale = transform.localScale;
    2. Vector3 newScale = currentScale * 2;
    3. transform.localScale = newScale;
     
    Last edited: Sep 16, 2020
  7. MrPuppyy

    MrPuppyy

    Joined:
    Nov 4, 2019
    Posts:
    40
    Yea thanks, haha. I was thinking a whole different bunch of stuff and Vectors never crossed my mind, haven;t used them much for it t cross my mind, thanks man big help for trying to understand what i was trying to say