So i have this script the checks if my mouse cursor is over the block and if it is i want the block to change color
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BasicBlockFunction : MonoBehaviour {
public GameObject Block;
public Color StartingColor;
public Color HighlightColor;
Color color;
Ray ray;
RaycastHit hit;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
MouseOver();
}
void MouseOver()
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
print(hit.collider.name);
Block.GetComponent<Renderer>().material.color = HighlightColor;
}
else
{
Block.GetComponent<Renderer>().material.color = StartingColor;
}
}
}
I want to change the color only for the gameobject i have my mouse on.
if(hit.gameObject.tag == "object") { // Do stuff. }
\$\endgroup\$