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 Trying to fix a Vector3 script

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

  1. MrPuppyy

    MrPuppyy

    Joined:
    Nov 4, 2019
    Posts:
    40
    So i made a vector3 script to change the scaling.

    Code (CSharp):
    1.     {
    2.         if (Input.GetKey("f"))  // If the player is pressing the "f" key
    3.         {
    4.             // makes the object shrink.
    5.             Vector3 CurrentScale = transform.localScale;
    6.             Vector3 newScale = CurrentScale + new Vector3(0, 0. - 0.4);
    7.             Transform.localScale = newScale;
    8.             Debug.Log("Shrunk!");
    9.         }
    10.  
    11.     }
    It gives me a console error at the - line 5 (just says identifier expected), and a "object reference is required for the non-static field method or property "Transform.localScale'
    i dont know what the problem is
     
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    Transform with a capital T is a class, if the class derives from MonoBehaviour, transform with a lowercase t is a reference to the game object's transform which the class is attached to.

    I'm guessing that you have used an uppercase in your code but have pasted it with a lowercase which is correct. Once you get past that though, floats need to be defined with an f at the end. So -0.4 will give an error, just add an f so it reads -0.4f instead.
     
  3. MrPuppyy

    MrPuppyy

    Joined:
    Nov 4, 2019
    Posts:
    40
    Vector3 newScale = CurrentScale + new Vector3(0, 0. - 0.4f);
    like this? transform is working now, but this is not working, still a error on -
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,741
    You have a period instead of a comma after the second 0
     
    PraetorBlue and Kurt-Dekker like this.