天天看點

滑鼠放在物體上,就彈出屬性框

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 ;
		
	}
}
           
滑鼠放在物體上,就彈出屬性框

繼續閱讀