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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity error

Discussion in 'Editor & General Support' started by gip1415, Jan 13, 2016.

  1. gip1415

    gip1415

    Joined:
    Jan 13, 2016
    Posts:
    3
    in my scrolling backgroundscript i have this error: CS0120: An object reference is required to access non-static member 'UnityEngine.renderer.material'
    this is my code:
    Renderer.material.mainTextureOffset = new Vector2 ((Time.time * speed) % 1,0f);
    Any help is welcome since I have no idea whats wrong
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,850
    You need to get the renderer component.

    Code (csharp):
    1. var renderer = GetComponent<Renderer>();
    2. Renderer.material.mainTextureOffset = new Vector2 ((Time.time * speed) % 1,0f);
     
  3. TwILeK

    TwILeK

    Joined:
    Sep 17, 2014
    Posts:
    54
    Last edited: Jan 13, 2016
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,850
    Yes my phone auto corrected and made it a capital letter :(