How to click in screen and change color in my sphere?
I have an sphere which change color if I click on it. But i need that user change the color of the sphere if he click screen, not in sphere.
Script change color :
public Material[] materials;
public Renderer rend;
private int index = 1;
// Use this for initialization
void Start () {
rend = GetComponent<Renderer> ();
rend.enabled = true;
}
public void OnMouseDown() {
if (materials.Length == 0) {
return;
}
if (Input.GetMouseButtonDown (0)) {
index += 1;
if (index == materials.Length + 1) {
index = 1;
}
print (index);
rend.sharedMaterial = materials [index - 1];
}
}
Answer by OpenXcell-Studio · Oct 14, 2016 at 12:50 PM
public Material[] materials;
public Renderer rend;
private int index = 1;
// Use this for initialization
void Start () {
rend = GetComponent<Renderer> ();
rend.enabled = true;
}
void Update() {
if (materials.Length == 0) {
return;
}
if (Input.GetMouseButtonDown (0)) {
index += 1;
if (index == materials.Length + 1) {
index = 1;
}
print (index);
rend.sharedMaterial = materials [index - 1];
}
}
I have one doubt more.
I have 3 cubes, with 3 colors, and my sphere has 3 colors also.
How i put when green sphere has collision with my green sphere ( for example), the game continues and when sphere and block are different color , the game finished.
script collision:
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class Colision : $$anonymous$$onoBehaviour {
//public GameObject HaloPrefab; // empty with halo applied to it...
void OnCollisionEnter(Collision col){
// GameObject halo = Instantiate(HaloPrefab) as GameObject;
if ( col.gameObject.name == "Cube") {
// Destroy (col.gameObject);
//halo.transform.SetParent (transform, false);
col.gameObject.SetActive(false);
}
if ( col.gameObject.name == "Cube(Clone)") {
// Destroy (col.gameObject);
col.gameObject.SetActive(false);
}
if (col.gameObject.name == "Cube1(Clone)") {
// Destroy (col.gameObject);
col.gameObject.SetActive (false);
}
if ( col.gameObject.name == "Cube2(Clone)") {
// Destroy (col.gameObject);
col.gameObject.SetActive(false);
}
if ( col.gameObject.name == "Cube3(Clone)") {
// Destroy (col.gameObject);
col.gameObject.SetActive(false);
}
}
}
I have that all the blocks are false if detect collision but i need what I told you up.
Your answer
Follow this Question
Related Questions
Animation won't stop (Solved) 2 Answers
Change color of cloned prefab objects 1 Answer
canvas child of another canvas issue 0 Answers
can you control 2 gameobject color values without having to reference both ? 0 Answers
How can i make a prefab character to be a child of an existing game object after purchasing 1 Answer