您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
43 行
1.2 KiB
43 行
1.2 KiB
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.Serialization;
|
|
|
|
namespace GameLobby.UI
|
|
{
|
|
//"Animates" the cursor when clicking
|
|
public class CursorHandler : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
Texture2D m_defaultTexture;
|
|
[SerializeField]
|
|
Texture2D m_ClickedTexture;
|
|
[SerializeField]
|
|
GameObject m_ClickVfxPrefab;
|
|
|
|
void Awake()
|
|
{
|
|
Cursor.SetCursor(m_defaultTexture, Vector3.zero, CursorMode.Auto);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
Cursor.SetCursor(m_ClickedTexture, Vector3.zero, CursorMode.Auto);
|
|
SpawnClickEffect();
|
|
}
|
|
|
|
if (Input.GetMouseButtonUp(0))
|
|
{
|
|
Cursor.SetCursor(m_defaultTexture, Vector3.zero, CursorMode.Auto);
|
|
}
|
|
}
|
|
|
|
void SpawnClickEffect()
|
|
{
|
|
var screenLocation = Camera.current.ScreenToWorldPoint(Input.mousePosition+Camera.current.transform.forward*10);
|
|
var clickVfxInstance = Instantiate(m_ClickVfxPrefab, screenLocation, Quaternion.identity);
|
|
Destroy(clickVfxInstance, 1);
|
|
}
|
|
}
|
|
}
|