为Hermes Agent配置自定义模型提供商并接入Taotoken的步骤
2026/5/7 15:02:53
视频链接:
https://www.bilibili.com/video/BV1wT9rYZEKe?spm_id_from=333.788.videopod.sections&vd_source=25b783f5f945c4507229e9dec657b5bb
本教程涉及到 Unity 常用组件、常用方法等核心知识点,掌握本教程相关知识后你就就可以快速掌握一些 Unity2D 常用组件了
Imags:静态图片
Prefabs:预设物体
Resources:动态资源
Scenes:场景
Scripts:脚本
创建游戏管理脚本 GameManager.cs
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassGameManager:MonoBehaviour{/// <summary>/// 游戏管理器实例/// </summary>publicstaticGameManagerinsta;/// <summary>/// 主界面/// </summary>publicMainPanelmainPanel;privatevoidAwake(){insta=this;}// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){}}红色小车挂载脚本 RedCar.cs
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassRedCar:MonoBehaviour{/// <summary>/// 移动速度/// </summary>privateintmoveSpeed=100;/// <summary>/// 移动方向/// </summary>publicintmoveDirection=0;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){//屏幕范围内左右移动if(moveDirection==-1&&transform.localPosition.x<=-490)return;if(moveDirection==1&&transform.localPosition.x>=490)return;transform.localPosition+=newVector3(moveDirection*moveSpeed*Time.deltaTime,0,0);}/// <summary>/// 碰撞显示结束界面/// </summary>/// <param name="collision"></param>privatevoidOnTriggerEnter2D(Collider2Dcollision){GameManager.insta.overPanel.ShowPanel();}}主界面挂载脚本 MainPanel.cs,拖拽相应物体
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEngine.UI;publicclassMainPanel:MonoBehaviour{/// <summary>/// 红色小车物体/// </summary>publicRedCarredCar;/// <summary>/// 分数文本/// </summary>publicTextscoreText;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){}/// <summary>/// 点击按钮向左移动/// </summary>publicvoidOnLeftMoveClick(){redCar.moveDirection=-1;}/// <summary>/// 点击按钮向右移动/// </summary>publicvoidOnRightMoveClick(){redCar.moveDirection=1;}}黄色小车挂载脚本 YellowCar.cs
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassYellowCar:MonoBehaviour{/// <summary>/// 移动速度/// </summary>privateintmoveSpeed=100;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){transform.localPosition-=newVector3(0,moveSpeed*Time.deltaTime,0);//向下移动if(transform.localPosition.y<=-1060)Destroy(gameObject);//如果移动到屏幕最底端则自动销毁}}红色小车挂载组件 Box Collider 2D 和 Rigidbody 2D
黄色小车挂载组件 Box Collider 2D
结束界面挂载脚本 OverPanel.cs
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEngine.SceneManagement;usingUnityEngine.UI;publicclassOverPanel:MonoBehaviour{/// <summary>/// 分数文本/// </summary>publicTextscoreText;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){}/// <summary>/// 显示面板/// </summary>publicvoidShowPanel(){Time.timeScale=0f;//游戏暂停gameObject.SetActive(true);}/// <summary>/// 点击按钮重新开始游戏/// </summary>publicvoidOnRestartClick(){Time.timeScale=1f;//游戏恢复gameObject.SetActive(false);SceneManager.LoadScene(0);}}GameManager.cs 新增结束界面变量
publicclassGameManager:MonoBehaviour{/// <summary>/// 游戏管理器实例/// </summary>publicstaticGameManagerinsta;/// <summary>/// 主界面/// </summary>publicMainPanelmainPanel;/// <summary>/// 结束界面/// </summary>publicOverPaneloverPanel;...主界面
...publicclassMainPanel:MonoBehaviour{/// <summary>/// 红色小车物体/// </summary>publicRedCarredCar;/// <summary>/// 分数文本/// </summary>publicTextscoreText;/// <summary>/// 分数数值/// </summary>publicintscore;/// <summary>/// 开始时间/// </summary>privatefloatstartTime;// Start is called before the first frame updatevoidStart(){startTime=Time.time;}// Update is called once per framevoidUpdate(){//更新分数score=(int)(Time.time-startTime);scoreText.text="分数:"+score;}...结束界面
...publicclassOverPanel:MonoBehaviour{/// <summary>/// 分数文本/// </summary>publicTextscoreText;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){scoreText.text="分数:"+GameManager.insta.mainPanel.score;}...创建黄色小车根目录
.../// <summary>/// 创建黄色小车上一次时间/// </summary>privatefloatlastTime;/// <summary>/// 黄色小车物体预设/// </summary>publicGameObjectpreYellowCarGo;/// <summary>/// 黄色小车根目录/// </summary>publicGameObjectyellowCarRootGo;// Start is called before the first frame updatevoidStart(){startTime=Time.time;lastTime=Time.time;}// Update is called once per framevoidUpdate(){//更新分数score=(int)(Time.time-startTime);scoreText.text="分数:"+score;//每过3秒生成一辆黄色小车if(Time.time-lastTime>=3f){CreateYellowCar();lastTime=Time.time;}}/// <summary>/// 点击按钮向左移动/// </summary>publicvoidOnLeftMoveClick(){redCar.moveDirection=-1;}/// <summary>/// 点击按钮向右移动/// </summary>publicvoidOnRightMoveClick(){redCar.moveDirection=1;}/// <summary>/// 创建黄色小车/// </summary>privatevoidCreateYellowCar(){//在x坐标为-490到490之间随机生成黄色小车GameObjectyellowCarGo=Instantiate(preYellowCarGo,yellowCarRootGo.transform);intrandomInt=Random.Range(-490,490);yellowCarGo.transform.localPosition=newVector3(randomInt,1060,0);}}创建游戏中音频物体
.../// <summary>/// 黄色小车根目录/// </summary>publicGameObjectyellowCarRootGo;/// <summary>/// 游戏进行中音频/// </summary>publicAudioSourcegameInAudioSource;// Start is called before the first frame updatevoidStart(){startTime=Time.time;// 开始时间赋值lastTime=Time.time;// 创建黄色小车上一次时间赋值gameInAudioSource.Play();//播放游戏进行音乐}...创建游戏结束音频物体
.../// <summary>/// 游戏技术音频/// </summary>publicAudioSourcegameOverAudioSource;.../// <summary>/// 显示面板/// </summary>publicvoidShowPanel(){Time.timeScale=0f;//游戏暂停gameObject.SetActive(true);//停止游戏进行音频,播放游戏结束音频if(GameManager.insta.mainPanel.gameInAudioSource.isPlaying){GameManager.insta.mainPanel.gameInAudioSource.Stop();}gameOverAudioSource.Play();}...usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassGameManager:MonoBehaviour{/// <summary>/// 游戏管理器实例/// </summary>publicstaticGameManagerinsta;/// <summary>/// 主界面/// </summary>publicMainPanelmainPanel;/// <summary>/// 结束界面/// </summary>publicOverPaneloverPanel;privatevoidAwake(){insta=this;}// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){}}usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEngine.UI;publicclassMainPanel:MonoBehaviour{/// <summary>/// 红色小车物体/// </summary>publicRedCarredCar;/// <summary>/// 分数文本/// </summary>publicTextscoreText;/// <summary>/// 分数数值/// </summary>publicintscore;/// <summary>/// 开始时间/// </summary>privatefloatstartTime;/// <summary>/// 创建黄色小车上一次时间/// </summary>privatefloatlastTime;/// <summary>/// 黄色小车物体预设/// </summary>publicGameObjectpreYellowCarGo;/// <summary>/// 黄色小车根目录/// </summary>publicGameObjectyellowCarRootGo;/// <summary>/// 游戏进行中音频/// </summary>publicAudioSourcegameInAudioSource;// Start is called before the first frame updatevoidStart(){startTime=Time.time;// 开始时间赋值lastTime=Time.time;// 创建黄色小车上一次时间赋值gameInAudioSource.Play();//播放游戏进行音乐}// Update is called once per framevoidUpdate(){//更新分数score=(int)(Time.time-startTime);scoreText.text="分数:"+score;//每过3秒生成一辆黄色小车if(Time.time-lastTime>=3f){CreateYellowCar();lastTime=Time.time;}}/// <summary>/// 点击按钮向左移动/// </summary>publicvoidOnLeftMoveClick(){redCar.moveDirection=-1;}/// <summary>/// 点击按钮向右移动/// </summary>publicvoidOnRightMoveClick(){redCar.moveDirection=1;}/// <summary>/// 创建黄色小车/// </summary>privatevoidCreateYellowCar(){//在x坐标为-490到490之间随机生成黄色小车GameObjectyellowCarGo=Instantiate(preYellowCarGo,yellowCarRootGo.transform);intrandomInt=Random.Range(-490,490);yellowCarGo.transform.localPosition=newVector3(randomInt,1060,0);}}usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEngine.SceneManagement;usingUnityEngine.UI;publicclassOverPanel:MonoBehaviour{/// <summary>/// 分数文本/// </summary>publicTextscoreText;/// <summary>/// 游戏技术音频/// </summary>publicAudioSourcegameOverAudioSource;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){scoreText.text="分数:"+GameManager.insta.mainPanel.score;}/// <summary>/// 显示面板/// </summary>publicvoidShowPanel(){Time.timeScale=0f;//游戏暂停gameObject.SetActive(true);//停止游戏进行音频,播放游戏结束音频if(GameManager.insta.mainPanel.gameInAudioSource.isPlaying){GameManager.insta.mainPanel.gameInAudioSource.Stop();}gameOverAudioSource.Play();}/// <summary>/// 点击按钮重新开始游戏/// </summary>publicvoidOnRestartClick(){Time.timeScale=1f;//游戏恢复gameObject.SetActive(false);SceneManager.LoadScene(0);}}usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassRedCar:MonoBehaviour{/// <summary>/// 移动速度/// </summary>privateintmoveSpeed=100;/// <summary>/// 移动方向/// </summary>publicintmoveDirection=0;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){//屏幕范围内左右移动if(moveDirection==-1&&transform.localPosition.x<=-490)return;if(moveDirection==1&&transform.localPosition.x>=490)return;transform.localPosition+=newVector3(moveDirection*moveSpeed*Time.deltaTime,0,0);}/// <summary>/// 碰撞显示结束界面/// </summary>/// <param name="collision"></param>privatevoidOnTriggerEnter2D(Collider2Dcollision){GameManager.insta.overPanel.ShowPanel();}}usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassYellowCar:MonoBehaviour{/// <summary>/// 移动速度/// </summary>privateintmoveSpeed=100;// Start is called before the first frame updatevoidStart(){}// Update is called once per framevoidUpdate(){transform.localPosition-=newVector3(0,moveSpeed*Time.deltaTime,0);//向下移动if(transform.localPosition.y<=-1060)Destroy(gameObject);//如果移动到屏幕最底端则自动销毁}}