usingSystem;usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingUnityEngine.EventSystems;usingUnityEngine.SceneManagement;publicclasswalk:MonoBehaviour{
publicGameObject[] gos;//获取每个目标点publicfloat speed =20;//用于控制移动速度int i =0;//用于记录是第几个目标点//float des; //用于存储与目标点的距离 // Use this for initializationpublicfloat x;publicfloat y;publicVector2 repos;//初始位置voidStart(){
i = PlayerPrefs.GetInt("i");if( i >0)
transform.position = gos[i -1].transform.position;}// Update is called once per framevoidUpdate(){
Moon();}privatevoidMoon(){
//移向目标
transform.position = Vector2.MoveTowards(this.transform.position, gos[i].transform.position, Time.deltaTime * speed);//移动到目标点进入答题场景if(transform.position == gos[i].transform.position){
SceneManager.LoadScene("Option");
i++;// 保存目标点下标
PlayerPrefs.SetInt("i", i);print(i);}}}
设置不销毁
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclasskeep:MonoBehaviour{
// Start is called before the first frame updatevoidStart(){
DontDestroyOnLoad(gameObject);}// Update is called once per framevoidUpdate(){
}}