第一步:准备工具
- unity
第二步:场景搭建
利用 unity做出开始UI场景
第三步:写代码
蛇头运动及蛇身生成
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class SnakeHead : MonoBehaviour {
public List<Transform> bodyList = new List<Transform>();
public float velocit = 0.3f;
public int step;
private int x;
private int y;
private Vector3 headPos;
private Transform canvas;
public GameObject bodyPrefab;
public Sprite[] bodySprites = new Sprite[2];
void Awake() {
canvas = GameObject.Find("Canvas").transform;
}
void Start()
{
InvokeRepeating("Move", 0, velocit);
x = step;y = 0;
}
void Update() {
if (Input