using UnityEngine;
using System.Collections;
public class Raycast : MonoBehaviour {
public Material green;
public Material brown;
public Material blue;
public bool IsGreen = false;
public bool IsBrown = false;
public bool IsBlue = false;
public RaycastHit Hit;
void Update()
{
if(Input.GetMouseButtonDown(0))
{
ChooseBlock();
}
}
void ChooseBlock()
{
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out Hit, Mathf.Infinity))
{
if(Hit.collider.tag == "block" && IsGreen == true)
{
IsBrown = false;
IsBlue = false;
Hit.collider.renderer.material = green;
}
else
{
if(Hit.collider.tag == "block" && IsBrown == true)
{
IsGreen = false;
IsBlue = false;
Hit.collider.renderer.material = brown;
}
if(Hit.collider.tag == "block" && IsBlue == true)
{
IsGreen = false;
IsBrown = false;
Hit.collider.renderer.material = blue;
}
}
}
}
}