C#
我在玩
这个作者很懒,什么都没留下…
展开
-
C#生命周期
void Awake(){Debug.Log(“Awake方法用于初始化并且永远只会执行一次”);}void OnEnable(){ Debug.Log("OnEnable在脚本每次激活时执行一次");}void Start(){ Debug.Log("Start在初始化后的下一帧执行,并且永远只会执行一次");}void OnDisable(){ Debug.Log("OnDisable在脚本每次不可用时,执行");}void OnDestroy()原创 2021-06-18 12:28:37 · 818 阅读 · 0 评论 -
Unity改变物体颜色
private void OnCollisionEnter(Collision collision){ gameObject.GetComponent<Renderer>().material.color = Color.green;}原创 2021-06-09 14:55:51 · 1133 阅读 · 2 评论 -
unity2018自带网络联机
空物体挂载原创 2021-06-07 10:04:15 · 295 阅读 · 0 评论 -
鼠标滑动检测
void Update(){ if (Input.GetMouseButtonDown(0)) { //记录鼠标按下的位置 first = Input.mousePosition; } if (Input.GetMouseButtonUp(0)) { //记录鼠标拖动的位置 second = Input.mousePosition; if (second.x < fir原创 2021-06-02 15:43:08 · 787 阅读 · 0 评论 -
获取系统本机时间
注意:加上using System;头文件Debug.Log(“time_now” + System.DateTime.Now); //当前时间(年月日时分秒)Debug.Log(“time_utcnow” + System.DateTime.UtcNow); // 当前时间(年月日时分秒)Debug.Log(“time_year” + System.DateTime.Now.Year); //当前时间(年)Debug.Log(“time_month” + System.Da原创 2021-06-02 15:36:31 · 213 阅读 · 0 评论 -
snake
设置分辨率关闭分辨率选择原创 2021-05-31 15:02:49 · 175 阅读 · 1 评论 -
打包游戏啊
这两个名字需要一致原创 2021-05-26 15:12:19 · 120 阅读 · 0 评论 -
unity暂停游戏,退出游戏
1.暂停游戏。Time.timeScale = 0;2.继续游戏。Time.timeScale = 1;3.重新开始。using UnityEngine.SceneManagement;SceneManager.LoadScene (0);其中,0,为游戏场景的索引号,具体索引号在build的时候加入场景的时候后面写的有。4.退出游戏application.Quit();...原创 2021-05-26 09:42:07 · 7468 阅读 · 6 评论 -
重载
void Update(){干饭(“我”, 12f,“食堂”); //顺序和位置要对上}//重载,在一个类下,同名不同参void 干饭(string 人物){ Debug.Log("人物"); return;}void 干饭(string 人物, float 时间){ Debug.Log("人物,时间"); return;}void 干饭(string 人物, float 时间, string 地点 ){ Debug.Log("人物,时间,地原创 2021-05-24 09:42:48 · 73 阅读 · 0 评论 -
消消乐
原创 2021-05-18 09:28:40 · 119 阅读 · 0 评论 -
Cinemachine相机(插件)自动跟随目标点
原创 2021-05-16 12:12:52 · 188 阅读 · 0 评论 -
动画混合,反向动力学IK
原创 2021-05-16 12:10:42 · 94 阅读 · 0 评论 -
动画混合树总结调用动画代码
原创 2021-05-15 22:41:40 · 75 阅读 · 0 评论 -
无代代码按钮隐藏image
创建image按住ALT,放大image创建3个image,隐藏两个3个ButtonButton拖入入上面的image,选中SetActive第一个按钮让第一个image显示第2个按钮让第2个image显示原创 2021-05-14 10:45:31 · 233 阅读 · 0 评论 -
UI按钮代码退出游戏,跳转场景
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;//退出程序public class UI3 : MonoBehaviour{public void Quit(){Application.Quit();}}原创 2021-05-14 08:47:36 · 383 阅读 · 0 评论 -
优化看不到到的物体,遮罩剔除
加载Occ视口将需要优化的物体选择中再Bake摄像机勾选这个参数原创 2021-05-08 16:01:59 · 114 阅读 · 0 评论 -
LOD Group
把高低模型拖入原创 2021-05-08 15:40:08 · 87 阅读 · 0 评论 -
接口
新建接口原创 2021-05-08 15:31:14 · 49 阅读 · 0 评论 -
协程
private void Update(){ if (Input.GetMouseButton(0)) { StartCoroutine("timeter");//调用协程 }}//协程,协助主程序进行IEnumerator timeter(){ //迭代器 yield return new WaitForSeconds(2);//延迟调用2秒 Debug.Log("程序运行了"); }...原创 2021-05-06 09:51:58 · 58 阅读 · 0 评论 -
unity三维物体拖动
直接将代码给要移动的物体就可三维物体拖动public class 三维物体拖动 : MonoBehaviour{Vector3 位置;float posX;float posY;float posZ;private void OnMouseDown(){ 位置 = Camera.main.WorldToScreenPoint(transform.position); posX = Input.mousePosition.x - 位置.x; posY = Input.原创 2021-04-28 17:04:35 · 146 阅读 · 0 评论 -
见缝插针
BallRotationusing System.Collections;using System.Collections.Generic;using UnityEngine;public class BallRotation : MonoBehaviour{public float speed = 90;void Update(){transform.Rotate(new Vector3(0, 0, speed*Time .deltaTime));}}GameManager..原创 2021-04-27 22:23:39 · 228 阅读 · 0 评论 -
UI分数与InputField
using UnityEngine.UI;//引用命名空间public int 分数;public Text Text;if (Input.GetMouseButtonDown(0)){分数++;//分数自身+1Text.text = 分数.ToString();//转为字符串类型}原创 2021-04-27 18:16:19 · 112 阅读 · 0 评论 -
Unity2D图片连续
首先导入一张图片更改图片属性,改为连续,Apply创建一个材质球材质球里拖入图片Hierarchy里创建画布图将上面的材质施加给Quad添加代码public Material 材质;Vector2 move;//移动public Vector2 speed;//速度void Start(){ 材质 = gameObject.GetComponent<Renderer>().material; //获取到渲染}void Update(){ mov原创 2021-04-27 10:55:01 · 523 阅读 · 0 评论 -
UnityUI与场景内物体对齐
在Hierarchy选中Canvas,调整属性,Render Mode改为World Space,再将Event Camera渲染拖入主摄像机直接调整Canvas的缩放就可以原创 2021-04-27 09:22:36 · 669 阅读 · 0 评论 -
unity接入支付宝付费
登录自己的支付宝原创 2021-04-25 10:53:26 · 1458 阅读 · 0 评论 -
Unity音频:AudioSource
1、AudioClip音频剪辑2、AudioSource组件对象添加AudioSource组件原创 2021-04-23 09:29:43 · 311 阅读 · 0 评论 -
Android sutudio
https://www.bmob.cn/原创 2021-04-22 14:39:25 · 170 阅读 · 1 评论 -
显示帧率
using UnityEngine;using System.Collections;public class FPSDisplay : MonoBehaviour{float deltaTime = 0.0f;void Update(){ deltaTime += (Time.unscaledDeltaTime - deltaTime) * 0.1f;}void OnGUI(){ int w = Screen.width, h = Screen.height;原创 2021-04-20 11:07:46 · 211 阅读 · 0 评论 -
射线
private Ray 射线;private Transform 位置;public GameObject 子弹预制体;void Start(){ 位置 = gameObject.GetComponent<Transform>();}void Update(){if (Input.GetMouseButton(0)) //点击鼠标左键{射线 = Camera.main.ScreenPointToRay(Input.mousePosition); //屏幕坐标转射线原创 2021-04-19 15:53:39 · 76 阅读 · 0 评论 -
unity基础移动
public float moveSpeed = 5f;void Update(){float H = Input.GetAxis(“Horizontal”);float V = Input.GetAxis(“Vertical”); transform.Translate(new Vector3(H, 0, V) * Time.deltaTime * moveSpeed, Space.World);}原创 2021-04-16 14:52:12 · 100 阅读 · 0 评论 -
自动寻路跳跃
首先给胶囊体添加NavMeshAgent,并烘焙地面给地面勾选这两个选项将Jump Distance 数值改大给胶囊体挂载代码原创 2021-04-14 16:18:38 · 87 阅读 · 0 评论 -
unity倍镜瞄准镜
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class ddddddd : MonoBehaviour{public GameObject 瞄准镜UI图;void Update(){ if(Input.GetMouseButtonDown(1)) { 瞄准镜UI图.SetActive(t原创 2021-04-14 11:47:36 · 296 阅读 · 0 评论 -
碰撞与触发标签判断
private void OnCollisionEnter(Collision collision){if (collision. collider. tag==""){}}private void onTriggerEnter(Collider other){if(other. tag-=""){}}原创 2021-04-13 09:20:26 · 284 阅读 · 0 评论 -
C# for循环猜数字
Random randmo = new Random(); int a= randmo.Next(0,10); for (; ; ) { int b = Convert.ToInt32(Console.ReadLine()); if(b != a) { Console.WriteLine("猜错"); ...原创 2021-04-02 10:50:58 · 280 阅读 · 0 评论