ich habe ein Verständigungsproblem zur Klassenvererbung.
Ich habe zwei Scripte, die jeweils auf ein GameObject zugewisen sind.
ColorChanger ist auf ein Zylinder zugewisen:
Code: Alles auswählen
using UnityEngine;
using System.Collections;
public class ColorChanger : RoteWurst {
	public float Zeit;
	
	// Use this for initialization
	void Start () {
	
	renderer.material.color = Color.green;
	//	Zeit = Time.deltaTime;
		Zeit = 0F;
	}
	
	// Update is called once per frame
	void Update () {
		if (Zeit > 10)
		{
			renderer.material.color = Color.red;
			
			
			
		}
		Zeit += Time.deltaTime;
	//	Debug.Log(Zeit);
		
	
	}
	
	override protected void OnMouseDown(){
		wurstZahl ++;
	}
}
Code: Alles auswählen
using UnityEngine;
using System.Collections;
public class RoteWurst : MonoBehaviour {
	public Texture2D Bild;
	public Texture2D Bild1;
	public Texture2D Bild2;
	public Texture2D Bild3;
	public int wurstZahl = 0;
	// Use this for initialization
	void Start () {
		renderer.material.mainTexture = Bild2;
	
	}
	
	// Update is called once per frame
	virtual protected void Update () {
		
		GrillWurstZahl();
	
	}
	
	virtual protected void OnMouseDown(){
		if (wurstZahl > 0){
		wurstZahl --;
		}
		else {
			Debug.Log("Es ist keine Wurst auf dem Grill");
		}
		
	}
	
	void GrillWurstZahl(){
		if (wurstZahl == 0)
		{
			renderer.material.mainTexture = Bild;	
		}
		if (wurstZahl ==1)
		{
				renderer.material.mainTexture = Bild1;	
		}
		if (wurstZahl == 2)
		{
				renderer.material.mainTexture = Bild2;	
		}
		if (wurstZahl == 3)
		{
				renderer.material.mainTexture = Bild3;	
		}
		
	}
}
Aber wenn ich auf den Zylinder drücke sollte die Zahl (wurstZahl) wieder hoch gehen, was sie nicht macht.
Bin für jede Info dankbar.
Gruß
Anubis