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);
}
}