using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//在其他物体上调用
public class Loder : MonoBehaviour
{
public GameObject gamemenager;
// Start is called before the first frame update
void Awake()
{
if (Gamemanager.Instence == null)
GameObject.Instantiate(gamemenager);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Gamemanager : MonoBehaviour
{
//单例模式
private static Gamemanager _instence;
public static Gamemanager Instence
{
get { return _instence; }
}
private void Awake()
{
_instence = this;
DontDestroyOnLoad(gameObject);//加载场景时不销毁
InitGame();
}
//bool交替执行
private bool sleepStep = true;
public void OnplayerMove()
{
if (sleepStep ==true )
{
sleepStep =false ;
}else
{
foreach (var enemy in enemyList )
{
enemy.Move();
}
sleepStep = true;
}
//角色移动后
if (player.targetpos.x == mapmanager.xc - 1.5f && player.targetpos.y == mapmanager.yc - 1.5f)
{
IsEnd = true;
//加载下一关
SceneManager.LoadScene(SceneManager .GetActiveScene ().buildIndex );
}
}
//场景加载后执行
private void OnLevelWasLoaded(int SceneLevel)
{
level++;
InitGame();
}
//失败后重新开始游戏
private void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
food = 100;
level -= level;
}