- Home /
Question by
Paul23758 · Oct 14, 2015 at 01:10 AM ·
clickonmousedown
Click & Materials
Hi all, i have problems of about 2 weeks with this, i have 4 capsules, i have a script that colors one capsule with a png texture randomly, i want to : if i click on the colored capsule to do score++ but if i click one of these 3 uncoloured -> GameOver(); i have a code but if i click , it returns gameover if the capsule is coloured and when it is not. i can't solve this, please help, Thanks.
using UnityEngine;
using System.Collections;
public class Click : MonoBehaviour {
int score;
public Material[] culoare = new Material[2];
void OnMouseDown() {
if (GetComponent<Renderer> ().material == culoare [1]) {
score++;
Debug.Log (score);
} else {
GameOver ();
}
}
void GameOver(){
Debug.Log ("Game Over");
}
}
untitled.png
(409.5 kB)
Comment
Best Answer
Answer by MadDevil · Oct 14, 2015 at 04:36 AM
try
if (GetComponent<Renderer>().sharedMaterial == culoare [1])
{
score++;
Debug.Log (score);
}
else
{
GameOver ();
}
Ok, thank you i try now! But i don't know why shared$$anonymous$$aterial :)