I Want it to set the material back to the material i setup when the reycast isint hitting the object anymore i only want it to be the hightlight material when its hitting it, Thanks in advance
private void OnMouseDrag()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Vector3 rayPoint = ray.GetPoint(distance);
rayPoint.y = 2;
transform.position = rayPoint;
// Debug.Log("m: " + Input.mousePosition);
// Debug.Log("r: " + rayPoint);
RaycastHit hit;
Ray BoardCheck = new Ray(transform.position, Vector3.down);
if (Physics.Raycast(BoardCheck, out hit))
{
if (hit.collider.tag == "BoardBlock")
{
// Debug.Log("Hit" + hit.collider.gameObject);
RaycastHitObject = hit.collider.gameObject;
RaycastHitObject.GetComponent<Renderer>().material = Hilight;
}
}
}
//IF MORE INFO IS NEEDED JUST ASK
}
A simple if else should do. If you hit your object, change its appearance, if not, change it back. All you need to do is to keep a reference to the object. Assign it via the inspector or inside the if on first hit. You already seem to be doing it (
RaycastHitObject) but don't seem to make use of it.