1. 程式人生 > >Highlighting物體邊緣發光外掛的基本用法

Highlighting物體邊緣發光外掛的基本用法

Highlighting Effect指令碼拖拽到Main camera上面

Hightlighting Controlller指令碼拖拽到要顯示發光的物體上面

 

Hightlighting Controlller內的內容根據需求寫,

例1:滑鼠進入物體發光,離開光熄滅

using UnityEngine;
using System.Collections;

public class HighlightingController : MonoBehaviour
{
	protected HighlightableObject ho;
	
	void Awake()
	{
		ho = gameObject.AddComponent<HighlightableObject>();
	}
	
	void Update()
	{
		AfterUpdate();
	}
    private void OnMouseEnter()
    {
        ho.ConstantOn(Color.green);
    }
    private void OnMouseExit()
    {
        ho.ConstantOffImmediate();
    }

    protected virtual void AfterUpdate() {}
}

例2:生成物體發光,3秒後消失

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class bringHighligting : MonoBehaviour {

    protected HighlightableObject ho;

    void Awake()
    {
        ho = gameObject.AddComponent<HighlightableObject>();
    }

    void Start () {
        ho.ConstantOn(Color.red);
        StartCoroutine(Timer());
	}
	
	// Update is called once per frame
	void Update () {
        AfterUpdate();
    }

    protected virtual void AfterUpdate() { }
    IEnumerator Timer()
    {
        yield return new WaitForSeconds(3f);
        ho.ConstantOffImmediate();
    }
}