• Unity 向量计算、欧拉角与四元数转换、输出文本、告警、错误、修改时间、定时器、路径、


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class c2 : MonoBehaviour
    {
        // 定时器
        float t1 = 0;
    
        void Start()
        {
            // 向量
            Vector3 v1 = new Vector3(0, 0, 2);
            Vector3 v2 = new Vector3(0, 0, 3);
    
            // 计算两个向量的夹角
            Debug.Log(Vector3.Angle(v1, v2));
            // 计算向量的模
            Debug.Log(v2.magnitude);
            // 两点之间的距离 (计算v1、v2 两个点之间的距离) 
            Debug.Log(Vector3.Distance(v1, v2));
            // 计算过程时,参数1 + (参数2 - 参数1)* 参数3
            // 插值 (0,0,0)  (0,0,1)   (0.1f) = 过程:0+ ((1-0)*0.1)  = (0,0,0.1)
            // 插值 (0,0,2)  (0,0,2)   (0.2f) = 过程:2+((2-2)*0.2) = (0,0,0.2)
            // 插值 (0,0,2)  (0,0,2)   (0.2f) = 过程:2+((2-2)*0.2) = (0,0,0.2)
            // 插值 (3,6,1)  (9,5,2)   (0.1f) =
            // 过程:3+ ((9-3)*0.1) = 3.6
            // 过程:6+ ((5-6)*0.1) = 5.9
            // 过程:1+ ((2-1)*0.1) = 1.1
            // 结果:(3.6,5.9,1.1)
            Debug.Log(Vector3.Lerp(new Vector3(3,6,1), new Vector3(9,5,2),0.1f));
    
    
            // 欧拉角 x y z
            // 四元数 x y z w
    
            // 欧拉角
            Vector3 rotate = new Vector3(60, 50, 0);
            // 四元数
            Quaternion quaternion = Quaternion.identity;
            // 欧拉角 转 四元数
            quaternion = Quaternion.Euler(rotate);
            Debug.Log("欧拉角 转 四元数");
            Debug.Log(quaternion);
            // 四元数 转 欧拉角
            Debug.Log("四元数 转 欧拉角");
            Debug.Log(quaternion.eulerAngles);
            // 这是一个朝向敌人的向量
            Vector3 dir = Vector3.left;
            // 获得一个朝向这个向量的旋转
            quaternion = Quaternion.LookRotation(dir);
    
    
            // 输出文本
            Debug.Log("输出文本");
            // 输出警告
            Debug.LogWarning("输出警告");
            // 输出错误
            // Debug.LogError("输出错误");
    
            // 时间相关
            // 游戏开始到现在所用时间
            // Debug.Log(Time.time);
    
            // 在编辑中-》项目设置-》时间:(时间尺度、固定时间步进)
            // 时间尺度:时间缩放数值
            Debug.Log(Time.timeScale);
            // 修改 时间尺度 (增加重量组件可以看效果)
            // Time.timeScale = 0.1f;
    
            // 固定时间步进:固定时间间隔
            Debug.Log(Time.fixedDeltaTime);
    
            // 路径相关
            // 找到 Assets 路径下的 某文件 (可读 某些不可写)若PC端可读可写
            Debug.Log(Application.dataPath + "/test.txt");
            // 持久化路径 可读可写  默认C盘
            Debug.Log(Application.persistentDataPath);
            // 在Asset文件下的 StreamingAssrts 文件夹内的文件 不会被加密(适合放配置文件)
            // 找到 在Asset文件下的 StreamingAssrts路径
            Debug.Log(Application.streamingAssetsPath);
            // 在Asset文件下的 Resources 文件夹内的文件 加载比较方便
            // 找到 临时文件 路径
            Debug.Log(Application.temporaryCachePath);
    
            // 判断是否 后台运行
            Debug.Log(Application.runInBackground);
            // 打开一个网址
            // Application.OpenURL("http://baidu.com");
            // 退出 (好像有问题,后面再尝试一下)
            // Application.Quit();
        }
    
        // Update is called once per frame
        void Update()
        {
            // 帧之间的间隔时间(跟硬件相关)
            // Debug.Log(Time.deltaTime);
    
            // 计时器
            t1 += Time.deltaTime;
    
            if (t1 >= 5)
            {
                Debug.Log("5秒到了");
                t1 = 0;
            }
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110

    在这里插入图片描述

    在这里插入图片描述

  • 相关阅读:
    眺望数据应用新态势|第八届腾讯云Techo TVP开发者峰会圆满落幕
    【java8】静态方法与默认方法
    Android okhttp3.0配置https信任所有证书
    C++内存管理 (new、delete)知识点+完整思维导图+实操图+深入细节通俗易懂建议收藏
    jupyter notebook中激活python的虚拟环境
    【前端笔记】ant-design-vue 3.x使用modal.method()自定义content内容小记
    漏洞复现-jquery-picture-cut 任意文件上传_(CVE-2018-9208)
    每天学习一个Linux命令之ssh
    SpringBoot 基础知识汇总 (史上最全)
    并查集的原理+例题
  • 原文地址:https://blog.csdn.net/qq_42102546/article/details/136407444