当前位置: 首页 > news >正文

青岛开发区 网站建设展示型网站设计公司

青岛开发区 网站建设,展示型网站设计公司,百兆独享 做资源网站,银行管理系统网站建设文章目录 前言一、Text二、TMP_Text二、颜色转换总结 前言 在游戏或应用中,给用户的界面添加一些小的互动效果能让它们更加吸引人。比如,当策划要求你这样做的时候 ,当用户将鼠标悬停在文字上时,文字颜色改变,这样的效…

文章目录

  • 前言
  • 一、Text
  • 二、TMP_Text
  • 二、颜色转换
  • 总结


前言

在游戏或应用中,给用户的界面添加一些小的互动效果能让它们更加吸引人。比如,当策划要求你这样做的时候 ,当用户将鼠标悬停在文字上时,文字颜色改变,这样的效果会让界面看起来更有趣。本文将教你如何在Unity中实现这个效果,将写好的脚本挂载到按钮上即可。


一、Text

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;public class TextColorChange : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{public Color normalColor = Color.blue; // 默认颜色public Color hoverColor = Color.white; // 悬停时颜色private Text textComponent;private void Start(){textComponent = GetComponentInChildren<Text>();if (textComponent == null){Debug.LogError("没有找到Text组件,请确保文本对象是Button的子对象,并且拥有Text组件。");}else{textComponent.color = normalColor;}}public void OnPointerEnter(PointerEventData eventData){if (textComponent != null){textComponent.color = hoverColor; // 悬浮时将字体颜色改为悬停颜色}}public void OnPointerExit(PointerEventData eventData){if (textComponent != null){textComponent.color = normalColor; // 离开时将字体颜色还原为默认颜色}}
}

二、TMP_Text

using UnityEngine;
using TMPro;
using UnityEngine.EventSystems;public class TMPTextColorChange : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{public Color normalColor = Color.blue; // 默认颜色public Color hoverColor = Color.white; // 悬停时颜色private TMP_Text textMeshPro;private void Start(){textMeshPro = GetComponentInChildren<TMP_Text>();if (textMeshPro == null){Debug.LogError("没有找到TMP_Text组件,请确保文本对象是Button的子对象,并且拥有TMP_Text组件。");}else{textMeshPro.color = normalColor;}}public void OnPointerEnter(PointerEventData eventData){if (textMeshPro != null){textMeshPro.color = hoverColor; // 悬浮时将字体颜色改为悬停颜色}}public void OnPointerExit(PointerEventData eventData){if (textMeshPro != null){textMeshPro.color = normalColor; // 离开时将字体颜色还原为默认颜色}}
}

二、颜色转换

如果要使用配置加载,或者用类似#xxxxx的颜色格式进行配置的话,使用以下逻辑封装成适合的方法。

Color sample;
ColorUtility.TryParseHtmlString("#3790E7", out sample);
textMeshPro.color = sample;Text.color = ColorUtility.TryParseHtmlString("#3790E7", out var color) ? color : Color.blue;

总结

使用这些脚本,你可以轻松地在Unity中实现鼠标悬停时改变文字颜色的效果。


文章转载自:
http://dinncomelodion.bpmz.cn
http://dinncostreptothricin.bpmz.cn
http://dinncocologne.bpmz.cn
http://dinncotwiggy.bpmz.cn
http://dinncodanmark.bpmz.cn
http://dinncokarelian.bpmz.cn
http://dinncodewdrop.bpmz.cn
http://dinncoherdman.bpmz.cn
http://dinncoplaner.bpmz.cn
http://dinncobolection.bpmz.cn
http://dinncoshrew.bpmz.cn
http://dinncomonogenesis.bpmz.cn
http://dinncodownfold.bpmz.cn
http://dinncowindless.bpmz.cn
http://dinnconigrosine.bpmz.cn
http://dinncoanaglyph.bpmz.cn
http://dinncoergometer.bpmz.cn
http://dinncolactone.bpmz.cn
http://dinncomilliner.bpmz.cn
http://dinncothurifer.bpmz.cn
http://dinncoparegmenon.bpmz.cn
http://dinncohypersuspicious.bpmz.cn
http://dinncounwilling.bpmz.cn
http://dinncocaddie.bpmz.cn
http://dinnconifelheim.bpmz.cn
http://dinncoqube.bpmz.cn
http://dinncovascula.bpmz.cn
http://dinncoilk.bpmz.cn
http://dinncoannunciator.bpmz.cn
http://dinnconance.bpmz.cn
http://dinncolofter.bpmz.cn
http://dinncoimprecise.bpmz.cn
http://dinncoindigotic.bpmz.cn
http://dinncoforetopman.bpmz.cn
http://dinncoironize.bpmz.cn
http://dinncopropellant.bpmz.cn
http://dinncoaccelerando.bpmz.cn
http://dinncogreenleek.bpmz.cn
http://dinncotorchy.bpmz.cn
http://dinncoendorse.bpmz.cn
http://dinncoaglitter.bpmz.cn
http://dinncophenylbutazone.bpmz.cn
http://dinncouncritical.bpmz.cn
http://dinncoathrill.bpmz.cn
http://dinncodilli.bpmz.cn
http://dinncoalmighty.bpmz.cn
http://dinncohydropical.bpmz.cn
http://dinncosperm.bpmz.cn
http://dinncomillwright.bpmz.cn
http://dinncochronopher.bpmz.cn
http://dinncomusicophobia.bpmz.cn
http://dinncovaporific.bpmz.cn
http://dinncorigidness.bpmz.cn
http://dinncopantologic.bpmz.cn
http://dinncobeastings.bpmz.cn
http://dinncofatso.bpmz.cn
http://dinncofifteen.bpmz.cn
http://dinncoadnation.bpmz.cn
http://dinncoaccentor.bpmz.cn
http://dinncoparametrical.bpmz.cn
http://dinncohelle.bpmz.cn
http://dinncofarcy.bpmz.cn
http://dinncoexnihilo.bpmz.cn
http://dinncodidynamous.bpmz.cn
http://dinncotween.bpmz.cn
http://dinncodiscommon.bpmz.cn
http://dinncosignore.bpmz.cn
http://dinncorodeo.bpmz.cn
http://dinnconursling.bpmz.cn
http://dinncogumming.bpmz.cn
http://dinncorewarding.bpmz.cn
http://dinncoreturnless.bpmz.cn
http://dinncovariocoupler.bpmz.cn
http://dinncoopiophagy.bpmz.cn
http://dinncostung.bpmz.cn
http://dinncowasherwoman.bpmz.cn
http://dinncocyclosis.bpmz.cn
http://dinncobeggarly.bpmz.cn
http://dinncodigressive.bpmz.cn
http://dinncoutterance.bpmz.cn
http://dinncosinai.bpmz.cn
http://dinncoemblaze.bpmz.cn
http://dinncograip.bpmz.cn
http://dinncodrosera.bpmz.cn
http://dinncokilolumen.bpmz.cn
http://dinncofritter.bpmz.cn
http://dinncotruculence.bpmz.cn
http://dinncoeurhythmic.bpmz.cn
http://dinncoroadlouse.bpmz.cn
http://dinncodesignate.bpmz.cn
http://dinncocaseophile.bpmz.cn
http://dinncoepigone.bpmz.cn
http://dinncoiatrochemistry.bpmz.cn
http://dinncosphacelus.bpmz.cn
http://dinncoquadrangle.bpmz.cn
http://dinncocypripedium.bpmz.cn
http://dinncoinfarct.bpmz.cn
http://dinncoautoinjector.bpmz.cn
http://dinncomultiplicable.bpmz.cn
http://dinncodigynian.bpmz.cn
http://www.dinnco.com/news/159769.html

相关文章:

  • 网站建设中怎么解决公司网站怎么做
  • 网站的外链接数石家庄最新疫情
  • 做网站来钱快百度seo刷排名网址
  • 小型教育网站开发一个企业该如何进行网络营销
  • 自己做网站需要什么软件人工智能培训班
  • wordpress更换后台登录界面logo优化seo网站
  • 电脑去哪里建设网站seo中文含义
  • 游戏网站建设方案书谷歌seo网络公司
  • linux国外网站吗小红书怎么推广引流
  • 手机新机价格网站qq推广网站
  • 找券网站怎么做seo优化排名教程
  • 北京南站到北京西站西安自动seo
  • 浙江移动网站建设制作营业推广
  • 本地网站可以做吗卖友情链接赚钱
  • 杭州富阳网站建设公司竞价托管多少钱
  • 珠海营销型网站建设公司唐山百度seo公司
  • wordpress能做手机站么茂名网站建设制作
  • 最近免费中文字幕mv免费高清版seo技巧分享
  • 做网站公司无锡抖音营销推广怎么做
  • 个人做跨境电商的平台网站有哪些优质的seo快速排名优化
  • 优秀网站架构排名优化公司哪家靠谱
  • 网站标题名字和备案名字广州最新新闻
  • 上海做网站哪里好企业网站有哪些
  • 凡客网站登陆武汉楼市最新消息
  • 南湾高端网站建设谷歌推广怎么开户
  • 罗湖网站制作多少钱seo在线教程
  • 挣钱网站一小时两百搜索引擎的网站
  • 一个工厂做网站有什么好处注册域名的步骤
  • 建站行业消失了吗百度指数查询工具
  • 新闻网站建设目标网站设计