unity 学习笔记(一)

目录

一、游戏素材获取itch.io

二、图片分割

三、实现人物移动

3.1设置碰撞边界

3.2设置刚体

3.3编写脚本


一、游戏素材获取itch.io

unity游戏人物素材可以到itch.io网站上寻找

可以避免很多像人物角色背景不透明问题,因为itch.io上的素材包背景大多已经处理好了

可以省去很多功夫。

二、图片分割(切片)

可以通过切片做出动画效果

推荐自动分割:

1、按照行列(推荐)

2、按照大小

无法自动分割的时候手动切片

三、实现人物移动

3.1设置碰撞边界

组件:Box Collider 2D或者Circle Collider 2D

3.2设置刚体

组件:Rigidbody

3.3编写脚本

组件:new script

using System.Collections;
using System.Collections.Generic;
using UnityEditor.Tilemaps;
using UnityEngine;

public class move : MonoBehaviour
{
    // Start is called before the first frame update
    public float speed;
    Rigidbody2D rb;
    bool facingRight = true;
    void filp() {
        
        transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
        facingRight = !facingRight;
    }

    
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        
    }

    // Update is called once per frame
    void Update()
    {

        float input = Input.GetAxisRaw("Horizontal");
        if (input > 0 && facingRight == false)
        {
            filp();
        }
        else if (input < 0 && facingRight == true)
        {
            filp();
        }
        rb.velocity = new Vector2(input * speed, rb.velocity.y);
        
        
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值