//读Json
Player的移动:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.IO;
public class
Move : MonoBehaviour
{
int index;
Data d;
public float speed = 10;
public void Awake()
{
string path = Application.dataPath + "/Json/Pos.json";
string s = File.ReadAllText(path);
d = JsonUtility.FromJson<Data>(s);
for (int i = 0; i < d.data.Count; i++)
{
print(d.data[i].name);
}
}
void Update()
{
transform.Translate((d.data[index].pos-transform.position).normalized*Time.deltaTime*speed);
if (Vector3.Distance(transform.position, d.data[index].pos) < 0.2f) {
//transform.LookAt(d.data[index + 1].pos);
index++;
if (index == 5) {
index = 0;
}
}
}
}