An object reference is required to access non-static member `UnityEngine.Component.renderer'

I want to access a script on another script, so I need to put static on the function that I want to access but I’m having this error:

An object reference is required to access non-static member UnityEngine.Component.renderer’

This is my code:

using UnityEngine;
using System.Collections;


public class gifAnimate : MonoBehaviour
{
    static public Texture[] botao;
    static public float framesPerSecond = 10;
	static public int index;


    static public void PlayAnim()
    {
       index = (int) (Time.time * framesPerSecond) % botao.Length;
        renderer.material.mainTexture = botao[index];
    }
}

A method doesn’t have to be static to be called by another script, public is enough for this. What static means is that the method does not belong to an instance, but to the global class… Meaning it doesn’t have a renderer for example (only instances have them).

just remove your “static” keywords

Of course you’ll need a reference to the specific instance you want to call PlayAnim on. Maybe GameObject.Find() or something like that.

That seems to be right about removing the ‘static’. I am a rusty C++ programmer who’s learning c# and java for Unity(I’m still not sure when to use static…lol), but you might still have errors after removing the static references, that is because (for some reason) the ‘renderer’ in renderer.material.mainTexture needs to be properly declared at the start of your gifAnimate class. Your code should read:
using UnityEngine;
using System.Collections;

 public class gifAnimate : MonoBehaviour
 {
     public Renderer renderer; //***This is added to properly 'link' renderer
     public Texture[] botao;
     public float framesPerSecond = 10;
     public int index;
 
     public void PlayAnim()
     {
        index = (int) (Time.time * framesPerSecond) % botao.Length;
         renderer.material.mainTexture = botao[index];
     }
 }

I don’t know if you need any of those statics, but it seems the Renderer(capital R) is a non-static member and therefore needs a static reference to be accessed by static members? (Sometimes I miss QBasic…lol)
P.S. As a rule of thumb (especially when not familiar with all syntax and functions of a programming language), avoid using common programming words like renderer or render(they are likely to be reserved by Unity and/or 3rd-Party assets or scripts. Use rend or renderer_01 or something that is unlikely to be used by someone else as a common syntax word.