今天是第一天学用Unity做RPG。
开始总是报出CS0234错误,namespace"UnityEngine"不存在的问题。
经发现,下载dll无用,将setting中的net 2.0 subnet转为net2.0也无用。
更新到2017版本就好了
除此之外
利用sprite editor添加人物。
多帧人物要在里面点slice并apply。
之后拖其中一格出来
人物可以通过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