unity3d 按钮变色

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

public class UI_Control : MonoBehaviour {

	// Use this for initialization
	void Start () {

	}
	public Sprite[] SpriteTexture = new Sprite[3];
	SpriteRenderer Sprite_Renderer;
	// Update is called once per frame
	void Update () {

	}
	/// 
	/// OnMouseDown is called when the user has pressed the mouse button while
	/// over the GUIElement or Collider.
	/// 
	void OnMouseDown () {
		if (gameObject.name == "StartGame") {
			Sprite_Renderer = gameObject.GetComponent ();
			Sprite_Renderer.sprite = SpriteTexture[2];
		} else if (gameObject.name == "ExitGame") {
			Sprite_Renderer = gameObject.GetComponent ();
			Sprite_Renderer.sprite = SpriteTexture[2];
		}
	}
	/// 
	/// Called when the mouse enters the GUIElement or Collider.
	/// 
	void OnMouseEnter () {
		if(gameObject.name == "StartGame")
		{
			Sprite_Renderer = gameObject.GetComponent();
			Sprite_Renderer.sprite = SpriteTexture[1];
		}
		else if(gameObject.name == "ExitGame")
		{
			Sprite_Renderer = gameObject.GetComponent();
			Sprite_Renderer.sprite = SpriteTexture[1];
		}
	}
	/// 
	/// Called when the mouse is not any longer over the GUIElement or Collider.
	/// 
	void OnMouseExit()
	{
		if(gameObject.name == "StartGame")
		{
			Sprite_Renderer = gameObject.GetComponent();
			Sprite_Renderer.sprite = SpriteTexture[0];
		}
		else if(gameObject.name == "ExitGame")
		{
			Sprite_Renderer = gameObject.GetComponent();
			Sprite_Renderer.sprite = SpriteTexture[0];
		}
	}
}

 

你可能感兴趣的:(unity3d 按钮变色)