系列文章目录
第一章 角色运动的实现
前言
准备学习unity。未来可能工作用或者。。。不一定。
从B站M_studio博主的视频,开始跟着做学习。目前做到第五集弹跳部分,可以实现。
一、Unity 2D游戏入门学习?
直接从应用商店安装了unity,然后配了编辑器,跟着视频开始尝试,素材来自unity官方。
二、实操过程
1.代码
代码如下(示例):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playercontroller : MonoBehaviour
{
public Rigidbody2D rb;
public float speed;
public float jumpforce;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
Movement();
}
void Movement()
{
float Horizontalmove = Input.GetAxis("Horizontal");
float facedirection = Input.GetAxisRaw("Horizontal");
if (Horizontalmove != 0)
{
rb.velocity = new Vector2(Horizontalmove * Time.deltaTime, rb.velocity.y);
}
if (facedirection != 0)
{
transform.localScale = new Vector3(facedirection, 1, 1);
}
if (Input.GetButtonDown("Jump"))
{
rb.velocity = new Vector2(rb.velocity.x, jumpforce * Time.deltaTime); }
}
}
总结
`
主要定义角色和背景,只贴了代码和结果视频,在unity里面有很多操作。