render.material help?

So here is part of the script. It should change materials once the tile is beaten. However the material remains the same. I was told to try to create a dummy object and just use sharematerial. That does work but not the best option I wish to use. Any ideas?

using UnityEngine;

using System.Collections;

 

public class beatenby : MonoBehaviour {

 

public enum BeatenBy

{

    Fire,

    Poison,

    Water,

    Lightening,

    Ice

}

    

public class ChallengeInfo {

    public ChallengeInfo(GameObject thischallenger, BeatenBy challengerType) {

        challenger = thischallenger;

        type = challengerType;

    }

    public GameObject challenger;

    public BeatenBy type;

 

}

 

public BeatenBy beatsMe; //set this to whatever beats this in the inspector

public BeatenBy IBeat; //set this to whatever is beaten by this

 

public LayerMask scannedLayer; //set this to the layer of the objects to be evaluated in the inspector

public float scanRadius; //this is the radius in which other objects are found

[COLOR="#FF0000"]public Material newMaterial;[/COLOR]

    

void Update() {

    Collider[] cols = Physics.OverlapSphere(transform.position, scanRadius, scannedLayer);

        foreach (Collider col in cols){

        col.SendMessage("Challenge", new ChallengeInfo(this.gameObject, IBeat), SendMessageOptions.DontRequireReceiver);

        }

    }

    

bool alreadyBeaten = false;

public void Challenge(ChallengeInfo info) {

    if (alreadyBeaten == false  info.type == beatsMe) {

        alreadyBeaten = true;

        

    [COLOR="#FF0000"]if (alreadyBeaten == true){

        renderer.material = newMaterial;[/COLOR]

        Debug.Log(gameObject.name+ " was beaten by: "+ info.challenger.name);

        }

    }

}

 

void OnDrawGizmos() {

    Gizmos.DrawWireSphere(transform.position, 0.7f);

}

    

}

i just want to second that question as i had a similar problem where changing renderer.material.color does change the color seen in the inspector field and also instantiates the material but has no (visual) effect on the gameObject. Only renderer.sharedMaterial did.

I tried this method as well hoping to just change the texture but no dice…Any help please this is very frustrating.

using UnityEngine;
using System.Collections;

public class beatenby : MonoBehaviour {

public enum BeatenBy
{
    Fire,
    Poison,
    Water,
	Lightening,
	Ice
}
	
public class ChallengeInfo {
    public ChallengeInfo(GameObject thischallenger, BeatenBy challengerType) {
        challenger = thischallenger;
        type = challengerType;
    }
    public GameObject challenger;
    public BeatenBy type;

}

public BeatenBy beatsMe; //set this to whatever beats this in the inspector
public BeatenBy IBeat; //set this to whatever is beaten by this
	
public GameObject gameObject;
	
public Texture2D beatenTex = Resources.Load("") as Texture2D;
public Texture2D notbeatenTex = Resources.Load("") as Texture2D;

public LayerMask scannedLayer; //set this to the layer of the objects to be evaluated in the inspector
public float scanRadius; //this is the radius in which other objects are found

void Update() {
    Collider[] cols = Physics.OverlapSphere(transform.position, scanRadius, scannedLayer);
		foreach (Collider col in cols){
       	col.SendMessage("Challenge", new ChallengeInfo(this.gameObject, IBeat), SendMessageOptions.DontRequireReceiver);
	    }
	}
	
bool alreadyBeaten = false;
public void Challenge(ChallengeInfo info) {
    if (alreadyBeaten == false  info.type == beatsMe) {
	if (alreadyBeaten == false)
		gameObject.renderer.material.mainTexture = notbeatenTex;
		Debug.Log(gameObject.name+ " was beaten by: "+ info.challenger.name);
		}
		 else {
			if (alreadyBeaten == true) {
				gameObject.renderer.material.mainTexture = beatenTex;
		}
	}
}

void OnDrawGizmos() {
	Gizmos.DrawWireSphere(transform.position, 0.7f);
}
	
}

Bump. Anyone know what’s going on or another way to change my texture or material for an object?