环境:unity2021+urp
本教程教大家如何使用Unity创建一个RPG游戏,玩家可以在城镇场景中进行导航并寻找战斗,并在战斗中遇到不同类型的敌人。玩家可以向敌人施加不同的动作,如:常规攻击和撤离。这会是一个十分有趣的体验。
学习目标:角色寻路、相机跟随、熟悉战斗系统(如:状态机、追随、攻击效果等)
游戏画面
项目结构目录
部分核心代码
public class GameManager : Singleton<GameManager>
{public CharacterStats playerStats;//private CinemachineFreeLook followCamera;private CinemachineVirtualCamera virtualCamera;List<IEndGameObserver> endGameObservers = new List<IEndGameObserver>();protected override void Awake(){base.Awake();DontDestroyOnLoad(this);}public void RigisterPlayer(CharacterStats player){playerStats = player;//followCamera = FindObjectOfType<CinemachineFreeLook>();//if (followCamera != null)//{// followCamera.Follow = playerStats.transform.GetChild(2);// followCamera.LookAt = playerStats.transform.GetChild(2);//}virtualCamera = FindAnyObjectByType<CinemachineVirtualCamera>();if(virtualCamera != null){virtualCamera.Follow = playerStats.transform.GetChild(2);virtualCamera.LookAt = playerStats.transform.GetChild(2);}}public void AddObserver(IEndGameObserver observer){endGameObservers.Add(observer);}public void RemoveObserver(IEndGameObserver observer){endGameObservers.Remove(observer);}public void NotifyObservers(){foreach (var observer in endGameObservers){observer.EndNotify();}}public Transform GetEntrance(){foreach (var item in FindObjectsOfType<TransitionDestination>()){if (item.destinationTag == TransitionDestination.DestinationTag.ENTER)return item.transform;}return null;}
}
下载链接:RPGCourseDemo: unity官方案例,RPGDemo