How to change texture in script

Hello i have 3 objects and depending how much diamonds ive colleted i want to change texture on 3 objects(stars) .
tried this
star1.GetComponent.material.maintexture = Star;
but here comes ERROR its a method not valid in a given context
any idea how to make it work?

//Sorry for so many questions but im a noob …

i think i fixed it but the rest doesnt work

using UnityEngine;
using System.Collections;

public class Stars : MonoBehaviour {
    public Texture Star;
   





    public int diamondRequired3Star;
    public int diamondRequired2Star;
    public int diamondRequired1Star;

   
    public Player diamondCount; // in the inspector it looks like its Gameobject when i want it to be INT!!!
    public GameObject star1;
    public GameObject star2;
    public GameObject star3;
    // Use this for initialization
    void Start () {
       

    }
   
    // Update is called once per frame
    void Update () {
   
    }
    public void EndLevel()
    {

        if ("diamondCount" == "diamondRequired3Star")
        {
            star1.GetComponent<Renderer>().material.mainTexture = Star;
            star2.GetComponent<Renderer>().material.mainTexture = Star;
            star3.GetComponent<Renderer>().material.mainTexture = Star;
            // 3 gwiazdki
        }
        if ("diamondCount"== "diamondRequired2Star")
        {
            star1.GetComponent<Renderer>().material.mainTexture = Star;
            star2.GetComponent<Renderer>().material.mainTexture = Star;
            // 2 gwiazdki
        }
        if ("diamondCount" == "diamondRequired1Star")
        {
            star1.GetComponent<Renderer>().material.mainTexture = Star;
            // 1 gwiazdka
        }
    }
}

and this is Player script

using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
using UnityEngine.UI;
using UnityEngine.SceneManagement; // tu zmienialem
public class Player : MonoBehaviour
{
    private Rigidbody rigidBody;
    public GameObject player;
    public int health = 3; // public bo narazie sprawdzam czy dziala
    private Vector3 startSpawn;
    public int diamondCount;
    public Text score;
    // Use this for initialization
    void Start()
    {
        startSpawn = transform.position;
        rigidBody = GetComponent<Rigidbody>();
        //score = GetComponent<Text>();

    }

    // Update is called once per frame
    void Update()
    {
   
        Debug.Log("H: " + CrossPlatformInputManager.GetAxis("Horizontal"));
        Debug.Log("V: " + CrossPlatformInputManager.GetAxis("Vertical"));
    }


    public void OnCollisionEnter(Collision col)
    {

        if (col.gameObject.name == "Shreder")
        {


            Respawn();
            if (health == 0)
            {
                Reset();
            }
        }

        if (col.gameObject.tag == "diamond")
        {
            Destroy(col.gameObject);
            diamondCount = 1 + diamondCount;
            SetCountText();

        }

        if (col.gameObject.tag == "finish")
        {
           SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }
    }

    public void Respawn()
    {
        transform.position = startSpawn;
        rigidBody.velocity = Vector3.zero;
        rigidBody.angularVelocity = Vector3.zero;
        health--;
    }

    public void Reset()
    {
        SceneManager.LoadScene("Przegrana");
       
        health = 3;
        diamondCount = 0;
    }




  

    public void  SetCountText()
    {
        score.text = diamondCount.ToString(); // it takes me here , error is "object reference not set to an instance of an object
   
    }
}

What errors do you get?

Anyway, it’s more efficient to create materials with different textures than changing the textures on the fly.

Note that accessing Renderer.material creates new material instances (or copies). If you don’t want that you should use Render.sharedMaterial instead.