插件资源:https://pan.baidu.com/s/1WpiIP_1B9NVtgVsLyQ0pcA
提取码:rkcj
1.给主摄像机添加脚本Highlighting Renderer脚本,路径为Assets/Plugins/Highlighting System/Scripts
2.给需要边缘高光的物体添加Highlighter脚本,路径一样
之后在摄像机下添加脚本就可以通过鼠标点击控制物体高亮
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HighlightingSystem;
using System.Text;
public class ClickController : MonoBehaviour
{
public Color hoverColor = Color.red; //鼠标滑过时的颜色
public Color ClickColor = Color.yellow; //点击过后物体的颜色
private void Update()
{
ClickPeople();
}
void ClickPeople()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //通过鼠标坐标生成射线
RaycastHit hit; //射线碰撞到的物体信息
if(Physics.Raycast(ray,out hit))
{
Transform tr = hit.collider.transform; //获取碰撞到的物体的transform
if (tr == null) return;
var highlighter = tr.GetComponent<Highlighter>(); //获得物体身上的Highlighter脚本
if (highlighter == null) return;
highlighter.Hover(hoverColor); //鼠标滑过时亮
if (Input.GetMouseButtonDown(0))
{
highlighter.isClick = !highlighter.isClick; //我在Highlighter脚本中添加了一个bool值判断物体是否被点击
}
if (highlighter.isClick)
{
highlighter.ConstantOn(ClickColor); //开启高亮
}
else
{
highlighter.ConstantOff(); //关闭高亮
}
}
}
}