Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question CS0120 An object reference is required for the non-static field, method, or property

Discussion in 'Getting Started' started by HiveMind_dev, May 7, 2022.

  1. HiveMind_dev

    HiveMind_dev

    Joined:
    May 6, 2022
    Posts:
    1
    hi, i just started using unity and the programing part its not my strong side , i got this error when i was using Transform.localScale making my character controller, i have been trying to solve it, watching tutorial, and nothing works.
    [ICODE]
    [/ICODE]
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Character_Controller : MonoBehaviour
    6. {
    7.    [SerializeField] Rigidbody2D rb;
    8.    [SerializeField] Transform gch;
    9.  
    10.  
    11.  
    12.    public float speed = 200f;
    13.    public Vector2 move;
    14.    public bool flip = false;
    15.  
    16.    void Start()
    17.    {
    18.      
    19.      
    20.  
    21.    }
    22.  
    23.  
    24.  
    25.     void FixedUpdate()
    26.     {
    27.        
    28.        rb.velocity = new Vector2(move.x * speed * Time.deltaTime , rb.velocity.y);
    29.      
    30.     }
    31.      void Update()
    32.      {
    33.  
    34.          move = new Vector2(Input.GetAxisRaw("Horizontal") , Input.GetAxisRaw("Vertical"));
    35.          if(move.x < 0 )
    36.          {
    37.             flip = true;
    38.          }
    39.        
    40.          else if(move.x > 0)
    41.          {
    42.             flip = false;
    43.          }
    44.         if (flip)
    45.         {
    46.          
    47.           Transform.localScale = new Vector3(-1f,1f,1f);
    48.         }
    49.         if (!flip)
    50.         {
    51.  
    52.            Transform.localScale = new Vector3(-1f,1f,1f);
    53.         }
    54.        
    55.  
    56.  
    57.       }
    58.      
    59.      
    60.    
    61.  
    62.    
    63. }
    64.  
    [ICODE]
    [/ICODE]