I have a simple object:
I want to create a highlight effect.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Map : MonoBehaviour
{
public Camera mapCamera;
public Text objectWasHit;
private Camera[] cameras;
private GameObject mouseOvered;
// Use this for initialization
void Start()
{
cameras = Camera.allCameras;
GameObject levels = GameObject.Find("_Level");
foreach (Transform child in levels.transform)
{
child.gameObject.AddComponent<Renderer>();
}
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.M))
{
if (mapCamera.enabled == false)
{
foreach (Camera cam in cameras)
{
cam.enabled = false;
}
mapCamera.enabled = true;
}
else
{
foreach (Camera cam in cameras)
{
cam.enabled = true;
}
mapCamera.enabled = false;
}
}
bool rcHit = false;
Vector3 mouse = Input.mousePosition;
Ray castPoint = mapCamera.ScreenPointToRay(mouse);
RaycastHit hit;
Debug.DrawRay(castPoint.origin, castPoint.direction * 1000, Color.magenta);
if (Physics.Raycast(castPoint, out hit, 1000))
{
rcHit = true;
if (mouseOvered != hit.collider.gameObject)
{
mouseOvered = hit.collider.gameObject;
}
objectWasHit.text = mouseOvered.name;
}
if (!rcHit && mouseOvered != null)
{
//do your thing to undo the material change
mouseOvered = null;
}
}
}
First I'm not sure if white color is the right way for highlighting. Second there is no startcolor since the object don't have any renderer or material at the first time. Then how can I make the highlight effect ?
sample * 1.0 = sample
\$\endgroup\$