Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active May 12, 2021 09:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/d832efacb5f5f4664fcf to your computer and use it in GitHub Desktop.
Save tsubaki/d832efacb5f5f4664fcf to your computer and use it in GitHub Desktop.
ボタンのクリックを押しながら背面をクリックするのを防ぐ
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class ChangeColor : MonoBehaviour {
MaterialPropertyBlock block;
void Start()
{
block = new MaterialPropertyBlock();
block.SetColor("_Color", Color.red);
}
void OnMouseUp ()
{
GetComponent<Renderer>().SetPropertyBlock(null);
}
void OnMouseDown()
{
if(EventSystem.current.IsPointerOverGameObject()){
return;
}
GetComponent<Renderer>().SetPropertyBlock(block);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment