今天是第一天学用Unity做RPG。

开始总是报出CS0234错误,namespace"UnityEngine"不存在的问题。

经发现,下载dll无用,将setting中的net 2.0 subnet转为net2.0也无用。

更新到2017版本就好了

除此之外

RPG第一天,Unity研究——报错解决及人物无法移动问题

利用sprite editor添加人物。

多帧人物要在里面点slice并apply。

之后拖其中一格出来

RPG第一天,Unity研究——报错解决及人物无法移动问题

人物可以通过wasd移动,代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class player : MonoBehaviour {
    [SerializeField]
    private float speed;


    private Vector2 direction;


// Use this for initialization
void Start () {
       
}

// Update is called once per frame
void Update () {
        GetInput();
        Move();
}


    public void Move() { 
    transform.Translate(direction*speed*Time.deltaTime);
}


    private void GetInput()
    {
        direction = Vector2.zero;
        if(Input.GetKey(KeyCode.W))
        {
            direction += Vector2.up;
        }
        if (Input.GetKey(KeyCode.A))
        {
            direction += Vector2.left;
        }
        if (Input.GetKey(KeyCode.S))
        {
            direction += Vector2.down;
        }
        if (Input.GetKey(KeyCode.D))
        {
            direction += Vector2.right;
        }


    }
}

注意调整speed

RPG第一天,Unity研究——报错解决及人物无法移动问题

相关文章:

  • 2022-12-23
  • 2021-05-14
  • 2021-11-19
  • 2021-12-01
  • 2022-01-01
  • 2022-12-23
  • 2021-12-11
  • 2022-12-23
猜你喜欢
  • 2022-02-01
  • 2023-03-31
  • 2021-10-03
  • 2022-03-08
  • 2021-05-25
  • 2021-05-17
  • 2023-02-20
相关资源
相似解决方案