Unity入门笔记(缘更)

内容来源SiKi学院的Luna's Fantasy

文章目录


一、基础知识

1.准备

Unity安装: https://unity.cn

2.基础知识

1.层级(Layer)

值越大,越后渲染,值大的游戏物体会覆盖值小的游戏物体。(初始为0)

Inspector->Sprite Renderer->Addititional Settings->Order in Layer.

2.轴心点

游戏物体的"锚点",以此为支点进行旋转,坐标点位置则是指轴心点的位置。
在Project中选择图片->Inspector->点击Sprite Editor进入编辑->下图黄色箭头所指位置的蓝色圆圈就是轴心点->移动蓝色圆圈可改变轴心点位置。(默认0.5,0.5)

3.预制体(Prefab)

是一个或者一系列组件的集合体,可以使用预制体实例化克隆体,后续可对克隆属性进行统一修改。

选择Assets右键->Create->folder->将名改为perfabs->...

4.刚体组件(Rigidbody)

使游戏物体能获得重力,接受外界的受力和扭力功能的组件,可通过脚本或者物理引擎为游戏对象添加钢铁组件。

2D游戏Gravity Scale设置为0,否则游戏物品会往下掉。

5.碰撞器组件(BoxCollider)

使游戏物体具有跟挂载刚体组件的游戏物体发送碰撞能力的组件。

二、代码

1.移动

csharp 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LunaController : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        //Application.targetFrameRate = 60;//帧率
    }
    // Update is called once per frame
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");//获取水平
        float vertical = Input.GetAxis("Vertical");//垂直
        Vector2 position = transform.position;
        position.x = position.x + 2*horizontal*Time.deltaTime;
        position.y = position.y + 2* vertical*Time.deltaTime;
        transform.position = position;   
    }
}
相关推荐
西岸行者2 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习
starlaky2 天前
Django入门笔记
笔记·django
勇气要爆发2 天前
吴恩达《LangChain LLM 应用开发精读笔记》1-Introduction_介绍
笔记·langchain·吴恩达
悠哉悠哉愿意2 天前
【单片机学习笔记】串口、超声波、NE555的同时使用
笔记·单片机·学习
勇气要爆发2 天前
吴恩达《LangChain LLM 应用开发精读笔记》2-Models, Prompts and Parsers 模型、提示和解析器
android·笔记·langchain
爱搞虚幻的阿恺2 天前
Niagara粒子系统-超炫酷的闪电特效(加餐 纸牌螺旋上升效果)
游戏·游戏引擎
_Li.2 天前
Simulink - 6DOF (Euler Angles)
人工智能·算法·机器学习·游戏引擎·cocos2d
qianshanxue112 天前
计算机操作的一些笔记标题
笔记
土拨鼠烧电路2 天前
笔记11:数据中台:不是数据仓库,是业务能力复用的引擎
数据仓库·笔记
weixin_424294672 天前
Unity 调用Steamworks API 的 SteamUserStats.RequestCurrentStats()报错
unity·游戏引擎·steamwork