all repos — RPG @ caae07a322fba99ea546629731cbb7cbd7a8ad4b

Fully functional 3D turn based role playing game coded in C# and base Unity.

working respawn logic
Marco Andronaco andronacomarco@gmail.com
Sat, 18 Apr 2020 14:50:56 +0200
commit

caae07a322fba99ea546629731cbb7cbd7a8ad4b

parent

a40a52248252949030dbbef05eb6f438175b8d4e

M Assets/Scenes/Level0.unityAssets/Scenes/Level0.unity

@@ -5120,13 +5120,13 @@ m_CorrespondingSourceObject: {fileID: 0}

m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 170076733} - m_LocalRotation: {x: 0.422118, y: 0.04407845, z: -0.020554056, w: 0.9052354} + m_LocalRotation: {x: 0.33430806, y: -0.5418431, z: 0.7183693, w: 0.2803386} m_LocalPosition: {x: 0, y: 900, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 50.000004, y: 5.5750003, z: 0} + m_LocalEulerAnglesHint: {x: 75, y: 43, z: 171} --- !u!1001 &233120629 PrefabInstance: m_ObjectHideFlags: 0

@@ -10412,7 +10412,6 @@ serializedVersion: 6

m_Component: - component: {fileID: 672366414} - component: {fileID: 672366413} - - component: {fileID: 672366415} m_Layer: 0 m_Name: GameMaster m_TagString: Untagged

@@ -10434,6 +10433,7 @@ m_Name:

m_EditorClassIdentifier: gold: 0 currentLevel: 0 + timer: 0 --- !u!4 &672366414 Transform: m_ObjectHideFlags: 0

@@ -10448,20 +10448,6 @@ m_Children: []

m_Father: {fileID: 0} m_RootOrder: 18 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &672366415 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 672366412} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: a292fa39de87e694885fa1cacd020276, type: 3} - m_Name: - m_EditorClassIdentifier: - timer: 0 - seconds: 0 --- !u!95 &692214256 stripped Animator: m_CorrespondingSourceObject: {fileID: 6787417573846047691, guid: b9089e56c5ff80b419c7f4aba9c5c421,
M Assets/Scenes/Level1.unityAssets/Scenes/Level1.unity

@@ -836,7 +836,6 @@ serializedVersion: 6

m_Component: - component: {fileID: 672366414} - component: {fileID: 672366413} - - component: {fileID: 672366415} m_Layer: 0 m_Name: GameMaster m_TagString: Untagged

@@ -872,20 +871,6 @@ m_Children: []

m_Father: {fileID: 0} m_RootOrder: 10 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &672366415 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 672366412} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: a292fa39de87e694885fa1cacd020276, type: 3} - m_Name: - m_EditorClassIdentifier: - timer: 0 - seconds: 0 --- !u!95 &692214256 stripped Animator: m_CorrespondingSourceObject: {fileID: 6787417573846047691, guid: b9089e56c5ff80b419c7f4aba9c5c421,
M Assets/Scripts/Menu/EndGameManager.csAssets/Scripts/Menu/EndGameManager.cs

@@ -20,9 +20,9 @@

void Start(){ GameMaster gm = GameMaster.Instance; userScore = gm.gold; - string timeString = gm.GetTimerString(); //TODO: set text - scoreText.text = "You finished the game in " + timeString + "\nand you collected " + userScore + "g"; + scoreText.text = "You finished the game in " + gm.GetPlayTime() + "\nand you collected " + gm.gold + "g"; + gm.resetGame(); } public void saveHighScore()
M Assets/Scripts/Utility/GameMaster.csAssets/Scripts/Utility/GameMaster.cs

@@ -31,6 +31,7 @@ private BattleManager battle;

private GameObject player; private List<string> killedEnemies = new List<string>(); private string fighting = ""; + private bool loaded = false; private string enemyType; private Vector3 lastPosition; private Quaternion lastRotation;

@@ -121,14 +122,14 @@ #region Battaglia vinta o ritorno all'overworld

case "Level0": case "Level1": player = FindObjectOfType<NoJumpController>().gameObject; - - if (fighting != "") - { //return from battle - foreach (string enemy in killedEnemies) - { - GameObject.Find(enemy).SetActive(false); - } + + if(loaded || fighting != ""){ player.transform.SetPositionAndRotation(lastPosition, lastRotation); + loaded = false; + } + foreach (string enemy in killedEnemies) + { + GameObject.Find(enemy).SetActive(false); } break; #endregion

@@ -156,10 +157,8 @@ {

return enemyType; } - public string GetTimerString(){ - int seconds = Mathf.RoundToInt(timer % 60); - int minutes = Mathf.RoundToInt(seconds / 60); - return minutes.ToString("00") + ":" + seconds.ToString("00"); + public string GetPlayTime(){ + return UI.getPlayTimeString(timer); } #endregion

@@ -216,6 +215,7 @@ }

public void LoadManager(int cl, List<string> ke, int g, Dictionary<string, Stats> p, Inventory i, string f, Vector3 pos, Quaternion rot, float timerfloat) { + loaded = true; currentLevel = cl; killedEnemies = ke; gold = g;
D Assets/Scripts/Utility/Timer.cs

@@ -1,15 +0,0 @@

-using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class Timer : MonoBehaviour -{ - public float timer = 0f; - public int seconds; - - void Update() - { - timer += Time.deltaTime; - //seconds = (int)timer % 60; - } -}
D Assets/Scripts/Utility/Timer.cs.meta

@@ -1,11 +0,0 @@

-fileFormatVersion: 2 -guid: a292fa39de87e694885fa1cacd020276 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant:
M Assets/Scripts/Utility/UI.csAssets/Scripts/Utility/UI.cs

@@ -19,11 +19,14 @@ public static float TextSpeed = PlayerPrefs.GetFloat("TextSpeed", 0.015f);

public static float BattleSpeed = PlayerPrefs.GetFloat("BattleSpeed", 1f); public static bool displaying_text = false; + public static string getPlayTimeString(float timer){ + return Mathf.FloorToInt(timer / 60).ToString("00") + ":" + Mathf.RoundToInt(timer % 60).ToString("00"); + } public static void setSLButtonText(Button btn, int slot, bool load) { //Debug.Log("filling button " + btn.ToString()); - int seconds; - DateTime dt = GetSlotDateTime(slot, out seconds); + float timer; + DateTime dt = GetSlotDateTime(slot, out timer); if(dt == default) { if(load)

@@ -36,13 +39,13 @@ }

btn.GetComponentInChildren<Text>().text = "Empty"; } else { - btn.GetComponentInChildren<Text>().text = dt.ToString(SaveDateFormat) + "\nPlay time " + Mathf.Floor(seconds / 60).ToString("00") + ":" + seconds.ToString("00"); + btn.GetComponentInChildren<Text>().text = dt.ToString(SaveDateFormat) + "\nPlay time " + getPlayTimeString(timer); btn.enabled = true; } } - public static DateTime GetSlotDateTime(int slot, out int seconds) + public static DateTime GetSlotDateTime(int slot, out float timer) { if (File.Exists(Application.persistentDataPath + "/game" + slot + ".save")) {

@@ -50,12 +53,12 @@ BinaryFormatter bf = new BinaryFormatter();

FileStream file = File.Open(Application.persistentDataPath + "/game" + slot + ".save", FileMode.Open); Save save = (Save)bf.Deserialize(file); file.Close(); - seconds = Mathf.RoundToInt(save.timerfloat % 60); + timer = save.timerfloat; return save.timestamp; } else { - seconds = 0; + timer = 0; return default; } }