1、NGUI
using UnityEngine;
using System.Collections;
public class xinCK : MonoBehaviour {
public GameObject cube;
public GameObject sphere;
public GameObject capsule;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnMouseEnter()//当鼠标进入
{
renderer.material.color = Color.red ;
//
if (tag == "Cube") {
cube.SetActive (true);
} else if (tag == "Sphere") {
sphere.SetActive (true);
} else if (tag == "Capsule") {
capsule.SetActive (true);
}
}
void OnMouseExit() //当鼠标退出
{
cube.SetActive (false);
sphere.SetActive (false);
capsule.SetActive (false);
renderer.material.color = Color.white ;
}
}
2、GUI
using UnityEngine;
using System.Collections;
public class ck : MonoBehaviour {
private bool IsOver = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
if (IsOver) {
GUI.Label (new Rect (Screen.width * 0.5f - 400 / 2, Screen.height * 0.3f - 100 / 2, 400, 100), "生命再战");
}
}
void OnMouseEnter()//当鼠标进入
{
IsOver = true;
OnGUI ();
renderer.material.color = Color.red ;
//
}
void OnMouseExit() //当鼠标退出
{
IsOver = false;
renderer.material.color = Color.white ;
}
}