随笔分类 -  Unity学习

学习Unity的笔记和一些问题解决方案
摘要:## 在Editor模式中执行组件内部的public字段/方法 > 1.确定绑定的组件 2. 创建GUI按钮 ``` [CustomEditor(typeof(Camera))] public class TestInspector : Editor { /// /// Inspector扩展,在对 阅读全文
posted @ 2023-08-18 17:49 lxp_blog 阅读(53) 评论(0) 推荐(0) 编辑
摘要:原因是没有勾选“auto refresh” 阅读全文
posted @ 2022-12-14 16:19 lxp_blog 阅读(87) 评论(0) 推荐(0) 编辑
摘要:问题 当分辨率发生变化后,UI上的粒子特效就会发生问题,比如:粒子特效无法贴合UI,UI大小发生变化,而粒子没有发生变化,如下图: using System.Collections; using System.Collections.Generic; using UnityEngine; publi 阅读全文
posted @ 2022-11-16 21:51 lxp_blog 阅读(126) 评论(0) 推荐(0) 编辑
摘要:问题 有多个UI,身上都有粒子特效时,为了防止不同粒子之间的冲突,我们需要决定这些粒子排序。 大致步骤:可以利用Canvas组件去修改UI的排序,再通过脚本控制UI子物体粒子特效的排序。 如下图,通过脚本中sortingOrder变量排序,值越大,越靠前 using System.Collectio 阅读全文
posted @ 2022-11-16 21:41 lxp_blog 阅读(574) 评论(0) 推荐(0) 编辑
摘要:洗牌算法 在遍历数组过程中,从i->length中随机获得一个下标 让该下标得元素与下标为i元素交换。 public static T[] ShuffleArray<T>(T[] array, int seed) { System.Random prng = new System.Random(se 阅读全文
posted @ 2022-10-30 11:38 lxp_blog 阅读(120) 评论(0) 推荐(0) 编辑
摘要:吸附功能 使得物体在两个平面内移动,如果碰到Target就直接吸附在Target上 步骤 给两个平面设置层Layer= Plane Target的Tag标签为Target 挂载脚本 代码 OnMouseDown():当点击到物体后才能让isMove变为true; 阅读全文
posted @ 2022-06-12 16:30 lxp_blog 阅读(1338) 评论(0) 推荐(0) 编辑
摘要:Time.timeScale的详解 Cursor.lockState关于鼠标锁定 UnityAPI:velocity属性——刚体速度 Rigidbody.velocity 的陷阱 transform.TransformDirection的使用 动画映射到变量 在角色前面添加射线并且检测碰撞 阅读全文
posted @ 2022-06-12 16:20 lxp_blog 阅读(36) 评论(0) 推荐(0) 编辑
摘要:射线检测碰撞 鼠标左键点击即可碰撞,注意被碰撞物体需要碰撞器组件 public LayerMask targetMask; if (Input.GetMouseButtonDown(0)) { Ray ray=Camera.main.ScreenPointToRay(Input.mousePosit 阅读全文
posted @ 2022-06-11 13:27 lxp_blog 阅读(135) 评论(0) 推荐(0) 编辑
摘要:Unity3D小功能:鼠标实现拖动物体(3D、UI) 阅读全文
posted @ 2022-06-11 13:23 lxp_blog 阅读(105) 评论(0) 推荐(0) 编辑
摘要:点乘和叉乘 画线 GL 源码 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Test : MonoBehaviour 阅读全文
posted @ 2022-05-27 21:40 lxp_blog 阅读(688) 评论(0) 推荐(0) 编辑
摘要:小球打方块 介绍 自动生成围墙 射线瞄准器,并且发射小球 角色控制移动(角色控制器CharacterController) 摄像机跟随 制作步骤 1. 构建基本场景 胶囊体需要添加:CharacterController,RigidBody组件 2. 控制角色移动(CharacterControll 阅读全文
posted @ 2022-05-25 20:38 lxp_blog 阅读(312) 评论(0) 推荐(0) 编辑
摘要:消除Unity黄色的线 只需要点击 Visualize 阅读全文
posted @ 2022-05-16 14:01 lxp_blog 阅读(361) 评论(0) 推荐(0) 编辑
摘要:GL C#实现 不管是画任何东西都需要Begin()和End()函数; 画线 using System.Collections; using System.Collections.Generic; using UnityEngine; public class GL_Line : MonoBehav 阅读全文
posted @ 2022-05-14 18:36 lxp_blog 阅读(98) 评论(0) 推荐(0) 编辑
摘要:协程 协程小案例 实现淡入淡出UI效果 StartCoroutine(Fade(Color.clear, new Color(0,0,0,.95f), 1));//调用 IEnumerator Fade(Color from, Color to, float time) { float speed 阅读全文
posted @ 2022-05-07 21:07 lxp_blog 阅读(88) 评论(0) 推荐(0) 编辑
摘要:# 存档方法 ## PlayerPrefs > 利用键值对的存储方式 > 存值的方法: PlayerPrefs.SetString("Name",t);//SetInt,SetFloat > 取值的方法: PlayerPrefs.GetString("Name","无");//GetInt,GetF 阅读全文
posted @ 2022-05-04 20:54 lxp_blog 阅读(155) 评论(0) 推荐(0) 编辑
摘要:UI管理器 任务: 1.所有面板的父类,2.UIMgr 所有UI控件都继承UIBehaviour 面板基类 找到相应空间 简化后 也存在问题:一个物体可以同时挂载两个组件 导致键相同,而值不同, 将值改为list<UIBehaviour>,Start-> Awake 时间提前一些 得到对应的控件脚本 阅读全文
posted @ 2022-05-02 21:22 lxp_blog 阅读(371) 评论(0) 推荐(0) 编辑
摘要:存档方式 代码 保存 xml 阅读全文
posted @ 2022-04-30 16:45 lxp_blog 阅读(62) 评论(0) 推荐(0) 编辑
摘要:寻路导航 1. 简单的寻路 先搭建出类似下面的结构 将你想作为障碍的物体放入一个空物体中 进入空物体点击Static,仅勾选 Navigation Static 即可 依次点击 Window->AI->Navigation,出现如下面板 默认设置,点击烘培bake 蓝色区域为可以通行的区域 红色物体 阅读全文
posted @ 2022-04-27 21:11 lxp_blog 阅读(251) 评论(0) 推荐(0) 编辑
摘要:音乐模块 检测音效是否在播放,没有播放就Destroy 需要利用到,MonoMgr执行Uptate 完整代码 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngin 阅读全文
posted @ 2022-04-25 21:05 lxp_blog 阅读(135) 评论(0) 推荐(0) 编辑
摘要:InputMgr 利用到事件中心 测试代码 添加Update监听 开关 代码汇总 using System.Collections; using System.Collections.Generic; using UnityEngine; public class InputMgr : Single 阅读全文
posted @ 2022-04-24 21:12 lxp_blog 阅读(54) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示
主题色彩