文章目录

  • 编译器推荐(Rider)
  • 坐标
    • 世界坐标系
    • 相对坐标系
  • 资源商店快捷入口
  • 地面制作
  • 脚本
    • 新建脚本
    • 生命周期
    • vs测试打印
  • 对象
    • 标签(自带集合属性)
    • 图层
  • 预设体
    • 创建预设体(cocos相同)
    • 定位预设体文件位置
    • 预设体添加、更新新内容
    • 预设体变体
  • 结构体
    • vector
  • 对象旋转
    • 欧拉角,四元数
  • 常用类
    • 时间类
    • Application类(资源路径,网页跳转)
  • 场景切换
    • SceneLoad场景加载
    • 异步场景加载
  • 操作监听
    • 键鼠监听
      • 虚拟轴
    • 触摸事件(手机触屏)
  • light(灯光)
    • directional(定向光)
    • spot(手电筒)
    • point(灯泡)
    • 阴影
  • 碰撞器、碰撞回调
  • 触发器

编译器推荐(Rider)

jet brain旗下软件,多好用不用我多说了

坐标

世界坐标系

这个球就位于世界坐标系0,0,0,也就是正中心

相对坐标系

相对于父Sphere的坐标系

资源商店快捷入口

地面制作


地形、山、树、草

脚本

新建脚本

第一种方式

第二种方式

生命周期

vs测试打印

对象

标签(自带集合属性)

图层


和摄像机这个属性对应,是否显示

预设体

创建预设体(cocos相同)

拖下来即可

定位预设体文件位置

预设体添加、更新新内容

预设体变体

只做了解,后期使用时再测试

结构体

vector

using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using UnityEngine;
using Vector3 = UnityEngine.Vector3;public class VectorTest : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){//向量,坐标,旋转,缩放Vector3 v = new Vector3();//创建结构体v = Vector3.zero;v = Vector3.right;Vector3 v2 = Vector3.forward;//计算两个向量夹角Debug.Log(Vector3.Angle(v,v2));//计算两点之间的距离Debug.Log(Vector3.Distance(v,v2));//点乘Debug.Log(Vector3.Dot(v,v2));//叉乘Debug.Log(Vector3.Cross(v,v2));//插值Debug.Log(Vector3.Lerp(Vector3.zero,Vector3.one,0.5f));//向量的模Debug.Log(v.magnitude);//规范化向量Debug.Log(v.normalized);}// Update is called once per framevoid Update(){}
}

对象旋转

欧拉角,四元数

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class RotateTest : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){//旋转:欧拉角,四元数Vector3 rotate = new Vector3(0,30,0);//创建初始化旋转0,0的欧拉角Quaternion quaternion = Quaternion.identity;//通过欧拉角转为四元数quaternion = Quaternion.Euler(rotate);//四元数转为欧拉角rotate = quaternion.eulerAngles;//看向一个物体quaternion = Quaternion.LookRotation(new Vector3(0, 0, 0));}// Update is called once per framevoid Update(){}
}

常用类

时间类

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class TimeTest : MonoBehaviour
{float timer = 0;// Start is called before the first frame updatevoid Start(){//游戏开始到现在所花的时间Debug.Log(Time.time);//时间缩放值Debug.Log(Time.timeScale);//固定时间间隔Debug.Log(Time.fixedDeltaTime);}// Update is called once per framevoid Update(){timer += Time.deltaTime;//上一帧到这一帧所用的游戏时间//Debug.Log(Time.deltaTime);//如果大于3秒if(timer > 3){Debug.Log("大于3秒了");}}
}

Application类(资源路径,网页跳转)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class ApplicationTest : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){//游戏数据文件夹路径(只读,加密压缩)Debug.Log(Application.dataPath);    //D:\Study\GitCode\unity\01_project\AssetsDebug.Log(Application.dataPath + "/测试文件夹");//持久化文件夹路径(不同平台的可存储文件的路径,不固定)Debug.Log(Application.persistentDataPath);//StramingAssets文件夹路径(只读,二进制文件加和配置文件)Debug.Log(Application.streamingAssetsPath); //D:\Study\GitCode\unity\01_project\Assets\streamingAssets//临时文件夹Debug.Log(Application.temporaryCachePath);  //C:/Users/29658/AppData/Local/Temp/DefaultCompany/01_project//控制是否在后台运行Debug.Log(Application.runInBackground);     //True(可以在buildSetting里设置后台运行关闭)//打开UrlApplication.OpenURL("https://www.baidu.com");//退出游戏// Application.Quit();}// Update is called once per framevoid Update(){}
}

场景切换

SceneLoad场景加载

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;public class SceneTest : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){//注意LoadScene会导致加载卡顿//后期还是要使用LoadSceneAsync异步加载//两个类//场景类//场景切换// SceneManager.LoadScene(0);  //通过索引跳转// SceneManager.LoadScene("MyScene");   //通过名称跳转//获取当前场景Scene scene = SceneManager.GetActiveScene();//场景nameDebug.Log(scene.name);//场景路径Debug.Log(scene.path);//场景索引Debug.Log(scene.buildIndex);//所有场景的数组GameObject[] gos = scene.GetRootGameObjects();Debug.Log(gos.Length);//场景管理类//创建新场景,动态创建场景,压缩内存占用SceneManager.CreateScene("newScene");//已加载场景个数,场景计数Debug.Log(SceneManager.sceneCount);//卸载场景SceneManager.UnloadSceneAsync("newScene");//场景替换//使MyScene替换当前场景,独立加载// SceneManager.LoadScene("MyScene",LoadSceneMode.Single);//场景叠加,同时加载,两个场景物体叠加SceneManager.LoadScene("MyScene",LoadSceneMode.Additive);}// Update is called once per framevoid Update(){}
}

异步场景加载

using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json.Serialization;
using UnityEngine;
using UnityEngine.SceneManagement;public class AsyncTest : MonoBehaviour
{AsyncOperation operation;// Start is called before the first frame updatevoid Start(){StartCoroutine(loadScene());}//携程方法用来异步加载场景IEnumerator loadScene(){operation = SceneManager.LoadSceneAsync("MyScene"); //参数可以用索引或者名称//实现加载完场景时不自动跳转,需要用户手动点击“进入游戏”operation.allowSceneActivation = false; yield return operation;}private float timer = 0;// Update is called once per framevoid Update(){//输出加载进度0-0.9(可以制作进度条)Debug.Log(operation.progress);//如果>=5秒,才可以跳转if (timer > 5){operation.allowSceneActivation = true;}}
}

操作监听

键鼠监听

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class KeyTest : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){//鼠标的点击//按下鼠标 0左键 1右键 2滚轮if (Input.GetMouseButtonDown(0)){Debug.Log("按下了鼠标左键");}//持续按下鼠标左键if (Input.GetMouseButton(0)){Debug.Log("持续按下鼠标左键");}//抬起鼠标左键if (Input.GetMouseButtonUp(0)){Debug.Log("抬起了鼠标左键");}//键盘操作//键盘按下AInput.GetKeyDown(KeyCode.A);//键盘持续按下AInput.GetKey(KeyCode.A);//抬起键盘按键AInput.GetKeyUp(KeyCode.A);}
}

虚拟轴

主要负责兼容问题

Edit-project setting - inputManager - Axes

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class AxesTest : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){//获取水平轴float horizontal = Input.GetAxis("Horizontal");float vertical = Input.GetAxis("Vertical");Debug.Log(horizontal + " " + vertical);//内置虚拟按键,也是在虚拟轴里配置if (Input.GetButtonDown("Jump")){Debug.Log("按下空格");}if (Input.GetButton("Jump")){Debug.Log("空格");}if (Input.GetButtonUp("Jump")){Debug.Log("空格");}}
}

触摸事件(手机触屏)

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class TouchTest : MonoBehaviour
{void Start(){//开启多点触摸Input.multiTouchEnabled = true;}void Update(){//判断单点触摸if (Input.touchCount == 1){//触摸对象Touch touch = Input.touches[0];//触摸位置Debug.Log(touch.position);//触摸阶段switch (touch.phase){case TouchPhase.Began:break;case TouchPhase.Moved:break;case TouchPhase.Stationary:break;case TouchPhase.Ended:break;case TouchPhase.Canceled:break;default:throw new ArgumentOutOfRangeException();}}//判断多点触摸if (Input.touchCount == 2){Touch touch = Input.touches[0];Touch touch1 = Input.touches[1];}}
}

light(灯光)

directional(定向光)

spot(手电筒)

point(灯泡)

阴影

碰撞器、碰撞回调

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class CollierCallBack : MonoBehaviour
{//创建一个预设体public GameObject PrefabTest;// Start is called before the first frame updatevoid Start(){}// Update is called once per framevoid Update(){}//监听发生碰撞private void OnCollisionEnter(Collision collsion){//落地后创建生成的预设体Instantiate(PrefabTest, transform.position, Quaternion.identity);//销毁自身Destroy(gameObject);//获取碰撞到的物体Debug.Log(collsion.gameObject.name);}//持续碰撞中private void OnCollisionStay(){}//碰撞结束private void OnCollisionExit(Collision other){}
}

触发器

   //触发开始private void OnTriggerEnter(Collider other){GameObject door = GameObject.Find("Door");if (door != null){//隐藏door.objectdoor.SetActive(false);}}//正在触发private void OnTriggerStay(Collider other){throw new NotImplementedException();}//触发结束private void OnTriggerExit(Collider other){throw new NotImplementedException();}

unity-概念与实操入门相关推荐

  1. 大数据与云计算学习计划 (一) 云计算系统管理 3 Linux系统命令行基础 (概念与实操)

    大数据与云计算学习计划 (一) 云计算系统管理 3 Linux系统命令行基础 (概念与实操) 一.文件颜色 二.命令 1.概念 命令的执行依赖于解释器(用户->解释器->内核->硬件 ...

  2. 大数据与云计算学习计划 (一) 云计算系统管理 6 Linux中RPM软件包管理操作 、 Yum软件包仓库操作(概念与实操)

    大数据与云计算学习计划 (一) 云计算系统管理 6 Linux中RPM软件包管理操作 . Yum软件包仓库操作(概念与实操) 一.RPM软件包管理 1.常见软件包类型 2.RPM包文件名特征 3.RP ...

  3. SLAM实操入门(六):连接Velodyne的16线激光雷达并可视化

    文章目录 前言 1 Velodyne激光雷达 2 配置网络 3 创建ROS工程 4 启动并可视化 5 录包与播放 总结 前言 好久没更新这部分了,最近在搞中期答辩的东西,简单补充一部分多线激光雷达建图 ...

  4. SLAM实操入门(七):使用Velodyne16线激光雷达与A-Loam进行三维SLAM

    文章目录 前言 1 A-LOAM 2 预备条件 2.1 Ubuntu和ROS 2.2 Ceres Solver(Ceres求解器) 2.3 PCL(Point Cloud Library) 3 创建A ...

  5. SLAM实操入门(五):无里程计仅使用激光雷达建图(GMapping算法)

    文章目录 前言 1 Gmapping算法 2 laser_scan_matcher库 2.1 安装laser_scan_matcher库 2.2 修改demo_gmapping.launch文件 3 ...

  6. 【Kubernetes】k8s的svc所有概念和实操详细说明(含镜像和代码)【2】【svc作用是端口转发相关】【含LB和ingress【反向代理】-部署使用】

    文章目录 service[svc]所有概念 环境准备 端口映射常规测试 创建pod 主机端口映射测试 修改pod副本数并测试 svc[service] 关于Service 定义Service的意义 没 ...

  7. SLAM实操入门(三):Ubuntu20.04安装Turtlebot3并运行SLAM例程仿真

    文章目录 前言 在Turtlebot3进行SLAM仿真 1 安装Turtlebot3依赖包 2 创建项目并安装Turtlebot3 3 使用Turtlebot3进行建图 4 使用扫描地图进行自动导航仿 ...

  8. PyTorch官方培训教程上线:从基本概念到实操,小白也能上手

    点击上方"视学算法",选择加"星标"或"置顶" 重磅干货,第一时间送达 明敏 发自 凹非寺 量子位 报道 | 公众号 QbitAI 你是否也 ...

  9. iSCSI target介绍及LIO实操入门

    前文介绍了iSCSI的基本架构及启动器的基本操作,也就是在客户端的操作.今天我们介绍一下目标器的相关概念.开源实现和基本操作.Linux操作系统下面有很多目标器的开源实现,比如LIO.SCST和TGT ...

  10. 【Kubernetes】k8s网络概念和实操详细说明【calico网络】【含docker不同容器网络互通配置,k8s网络互通配置】【1】

    文章目录 calico网络之间通信配置[docker容器互通流程配置] calico网络原理分析 一.Calico基本介绍 二.Calico结构组成 三.Calico 工作原理 四.Calico网络方 ...

最新文章

  1. VMware 收购 Kubernetes 初创公司 Heptio
  2. 就微软启动盗版系统黑屏的个人看法
  3. 检测单链表是否是回文
  4. HTTP 2.0与HTTP 1.0的区别 ?
  5. vue - v-if 注意点
  6. jzoj6342-[NOIP2019模拟2019.9.7]Tiny Counting【树状数组,容斥】
  7. 【51单片机快速入门指南】4.4:I2C 读取HMC5883L / QMC5883L 磁力计
  8. 挺好用的Markdown写法
  9. 偶然发现一个大佬写的 React 脚手架,叫Moderate, 用起来很方便
  10. html 360不识别,html 为什么在ie里显示正常在360浏览器不正常呢?
  11. java英语词汇_java常用的英语单词
  12. java if 并列_Java 并列if语句,一个判断失败后,后面的if就不执行了,为什么啊?...
  13. linux轮训创建文件夹,Linux文件和目录管理相关命令(三)
  14. PyTorch学习—19.模型的加载与保存(序列化与反序列化)
  15. Hype教程,如何设置字体样式?
  16. Kindle多看系统中字典
  17. python3大小写转换函数_python字符串大小写转换
  18. top命令输出解释以及load average 详解及排查思路
  19. Filter过滤器的作用
  20. docker与宿主机通信

热门文章

  1. Excel函数培训目录
  2. Hmac算法与对称加密算法
  3. 成功解决:Oracle中文乱码问题(很详细,很详细,很详细)
  4. Kaggle座头鲸识别top5解决方案
  5. linux ssh expect,linux命令expect实现ssh登陆
  6. mongodb查询错误:listDatabases failed NotMasterNoSlaveOk
  7. SQL 学习日记—存储过程
  8. 【JS】930- 更快的 async 函数和 promises
  9. Oracle建数据挖掘模型
  10. 自定义UILabel,具有居上/居下/居中的功能