Fixed player position

Added automatic player appearance, fixed teleports
This commit is contained in:
KrolMel 2022-10-01 15:39:24 +02:00
parent 9b6964256e
commit 2e648df55e
23 changed files with 27402 additions and 12589 deletions

View File

@ -51,6 +51,7 @@
<Compile Include="Assets\LetterText.cs" />
<Compile Include="Assets\Scripts\SceneManager\SceneTaskManager.cs" />
<Compile Include="Assets\Scripts\SettingsButton.cs" />
<Compile Include="Assets\Scripts\SceneManager\MainCharacter\MainCharacterManager.cs" />
<Compile Include="Assets\Scripts\UI\ISlot.cs" />
<Compile Include="Assets\Scripts\Enemies&apos; Scprits\Enemy.cs" />
<Compile Include="Assets\Scripts\Objects\GoldOre.cs" />

8
Assets/Resources.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3ee6e7ceeba1b814cb5310e2f2eaf155
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 4cb7163e44af59f4c9350005c199db3c
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -9,6 +9,10 @@ public class DoorBehaviour : MonoBehaviour
public string SceneName = "SampleScene";
public GameObject SaveController;
[SerializeField]
public Gateway gateway;
private void Awake()
{
if(Instance == null)
@ -34,7 +38,17 @@ public class DoorBehaviour : MonoBehaviour
public void ScenetToMoveTo()
{
// 1. Save all befor change scene
//saving info about used gate/door/teleport
OnMapAppearanceMethod.Gateway = OnMapAppearanceMethodEnum.Gateway;
PlayerPrefs.SetString("gateway.sourceMapName", gateway.currentMapName);
PlayerPrefs.SetString("gateway.nextMapName", gateway.nextMapName);
PlayerPrefs.SetFloat("gateway.respawnCoords.x", gateway.respawnCoords.x);
PlayerPrefs.SetFloat("gateway.respawnCoords.y", gateway.respawnCoords.y);
PlayerPrefs.SetFloat("gateway.respawnCoords.z", gateway.respawnCoords.z);
// 1. Save all before change scene
SaveController.GetComponent<SaveController>().SaveItems();
SaveController.GetComponent<SaveController>().SaveQuests();
SaveController.GetComponent<SaveController>().SaveInventory();

View File

@ -57,7 +57,9 @@ public class FollowingEnemy : Enemy
}
myRigidbody = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
target = GameObject.FindWithTag("Player").transform;
other = GameObject.FindWithTag("Player");
}
// Update is called once per frame

View File

@ -62,6 +62,7 @@ public class FollowingPatrollingEnemy : Enemy
myRigidbody = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
target = GameObject.FindWithTag("Player").transform;
other = GameObject.FindWithTag("Player");
}
// Update is called once per frame

View File

@ -1,6 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class Player : MonoBehaviour
{
@ -45,6 +46,8 @@ public class Player : MonoBehaviour
void Start()
{
Panel = GameObject.FindObjectsOfType<GameObject>(true).Where(sr => sr.gameObject.name == "YouDied").ToArray()[0];
healthBar = (HealthBar)FindObjectOfType<HealthBar>();
int continued = PlayerPrefs.GetInt("continued");
if (continued == 1)
{
@ -59,13 +62,16 @@ public class Player : MonoBehaviour
healthBar.SetMaxHealth(maxHealth.initialValue);
healthBar.SetHealth(currentHealth);
walkSpeed = 4f;
currentHealth = 10;
}
public void TakeDamage(float damage)
{
currentHealth = currentHealth - damage;
Debug.Log(currentHealth);
healthBar.SetHealth(currentHealth);
var em = dmgParticleSystem.emission;
em.enabled = true;
StartCoroutine(Timer());
@ -106,108 +112,108 @@ public class Player : MonoBehaviour
private void HandleInput()
{
if (Input.GetKeyDown(KeyCode.Space))
{
attackSword = true;
}
if (Input.GetKeyDown(KeyCode.LeftShift))
{
attackFist = true;
}
if(Input.GetKeyDown(KeyCode.X))
{
pickaxeInUse = true;
}
}
private void ResetValues()
{
attackSword = false;
attackFist = false;
pickaxeInUse = false;
}
void Update()
{
//if (canWalk == true)
//{
inputHorizontal = Input.GetAxisRaw("Horizontal");
inputVertical = Input.GetAxisRaw("Vertical");
myAnimator.SetFloat("moveX", inputHorizontal * walkSpeed);
myAnimator.SetFloat("moveY", inputVertical * walkSpeed);
if (inputHorizontal != 0)
{
myAnimator.SetFloat("speed", walkSpeed);
}
else if (inputVertical != 0)
{
myAnimator.SetFloat("speed", walkSpeed);
}
else
{
myAnimator.SetFloat("speed", 0);
if (Input.GetKeyDown(KeyCode.Space))
{
attackSword = true;
}
if (Input.GetKeyDown(KeyCode.LeftShift))
{
attackFist = true;
}
if(Input.GetKeyDown(KeyCode.X))
{
pickaxeInUse = true;
}
}
if (inputHorizontal == 1 || inputHorizontal == -1 || inputVertical == 1 || inputVertical == -1)
private void ResetValues()
{
myAnimator.SetFloat("lastMoveX", inputHorizontal);
myAnimator.SetFloat("lastMoveY", inputVertical);
attackSword = false;
attackFist = false;
pickaxeInUse = false;
}
void Update()
{
//if (canWalk == true)
//{
inputHorizontal = Input.GetAxisRaw("Horizontal");
inputVertical = Input.GetAxisRaw("Vertical");
myAnimator.SetFloat("moveX", inputHorizontal * walkSpeed);
myAnimator.SetFloat("moveY", inputVertical * walkSpeed);
if (inputHorizontal != 0)
{
myAnimator.SetFloat("speed", walkSpeed);
}
else if (inputVertical != 0)
{
myAnimator.SetFloat("speed", walkSpeed);
}
else
{
myAnimator.SetFloat("speed", 0);
}
if (inputHorizontal == 1 || inputHorizontal == -1 || inputVertical == 1 || inputVertical == -1)
{
myAnimator.SetFloat("lastMoveX", inputHorizontal);
myAnimator.SetFloat("lastMoveY", inputVertical);
}
timerRegen += Time.deltaTime;
if(timerRegen >= waitRegen)
{
startRegen = true;
}
if (startRegen == true)
{
timerTick += Time.deltaTime;
if(timerTick >= waitTick)
timerRegen += Time.deltaTime;
if(timerRegen >= waitRegen)
{
if(currentHealth < 10)
startRegen = true;
}
if (startRegen == true)
{
timerTick += Time.deltaTime;
if(timerTick >= waitTick)
{
currentHealth = currentHealth + 1;
healthBar.SetHealth(currentHealth);
timerTick = 0f;
if(currentHealth < 10)
{
currentHealth = currentHealth + 1;
healthBar.SetHealth(currentHealth);
timerTick = 0f;
}
}
}
PlayerPrefs.SetFloat("health", currentHealth);
//}
HandleInput();
}
PlayerPrefs.SetFloat("health", currentHealth);
//}
HandleInput();
}
void FixedUpdate()
{
if(canWalk == true)
{
if (inputHorizontal != 0 || inputVertical != 0)
void FixedUpdate()
{
if (inputHorizontal != 0 && inputVertical != 0)
if(canWalk == true)
{
inputHorizontal *= speedLimiter;
inputVertical *= speedLimiter;
if (inputHorizontal != 0 || inputVertical != 0)
{
if (inputHorizontal != 0 && inputVertical != 0)
{
inputHorizontal *= speedLimiter;
inputVertical *= speedLimiter;
}
rb.velocity = new Vector2(inputHorizontal * walkSpeed, inputVertical * walkSpeed);
}
else
{
rb.velocity = new Vector2(0f, 0f);
}
}
rb.velocity = new Vector2(inputHorizontal * walkSpeed, inputVertical * walkSpeed);
HandleAttacks();
ResetValues();
}
else
public void SaveCheckpoint()
{
rb.velocity = new Vector2(0f, 0f);
PlayerPrefs.SetFloat("health-S", currentHealth);
}
}
HandleAttacks();
ResetValues();
}
public void SaveCheckpoint()
{
PlayerPrefs.SetFloat("health-S", currentHealth);
}
}

View File

@ -11,6 +11,7 @@ public class RespawnScript : MonoBehaviour
public void RespawnOnCurrentScene()
{
mainCh = GameObject.FindGameObjectWithTag("Player");
Scene scene = SceneManager.GetActiveScene();
currentScene = scene.name;
SceneManager.LoadScene(currentScene);

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 56b5700f3ae9ef149bb959906fe6b684
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,105 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.SceneManagement;
using System;
public class MainCharacterManager : MonoBehaviour
{
[SerializeField]
public GameObject avatar;
[SerializeField]
public GameObject AvatarClone;
public Vector3 startPosition;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void Awake()
{
try
{
avatar = GetMainCharacterObject();
GameObject globalGUI = GameObject.FindGameObjectWithTag("GUI");
if (AvatarClone == null)
{
startPosition = InitCharacterPosition();
AvatarClone = GameObject.Instantiate(avatar, startPosition, Quaternion.identity);
}
}
catch (UnityException e)
{
Debug.Log(e);
}
//DynamicPanel.transform.localPosition = uiPanelTemplate.transform.position; // prevent overwritten position by... environment???
}
// Later here we will decide whether the player is loading a saved game, thus, a saved position
// In general we have 3 cases -> saved game and save position, new position on the map, and position after using teleport/door
private Vector3 InitCharacterPosition()
{
switch (OnMapAppearanceMethod.Gateway)
{
case OnMapAppearanceMethodEnum.Gateway:
{
if (SceneManager.GetActiveScene().name != PlayerPrefs.GetString("gateway.nextMapName") && PlayerPrefs.GetString("gateway.nextMapName") != "")
{
throw new Exception("Gateway says we should be somewhere else: " + PlayerPrefs.GetString("gateway.nextMapName"));
}
var x = PlayerPrefs.GetFloat("gateway.respawnCoords.x");
var y = PlayerPrefs.GetFloat("gateway.respawnCoords.y");
var z = PlayerPrefs.GetFloat("gateway.respawnCoords.z");
return new Vector3(x, y, z);
}
default:
{
return DefaultPlayerMapPosition();
}
}
}
private Vector3 DefaultPlayerMapPosition()
{
switch (SceneManager.GetActiveScene().name)
{
case "CaveEntrance":
{
return new Vector3(0.5f, -37, 10);
}
default:
{
return avatar.transform.position;
}
}
}
private GameObject GetMainCharacterObject()
{
/* Debug.Log("XDDDDD");
string[] obects = AssetDatabase.FindAssets("t:Object", new[] { "Assets/Resources/" });
foreach (string localObject in obects)
{
Debug.Log(AssetDatabase.GUIDToAssetPath(localObject));
}
return (GameObject)AssetDatabase.LoadAssetAtPath("Assets/Resources/ThePlayer.prefab", typeof(GameObject));*/
return Resources.Load("ThePlayer") as GameObject;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e11719a854a3211459e4fb55658c64c3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,23 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum OnMapAppearanceMethodEnum
{
NewGame = 0,
LoadGame = 1,
Gateway = 2
//maybe respawn too
}
public class OnMapAppearanceMethod : MonoBehaviour
{
public static OnMapAppearanceMethodEnum Gateway { get; set; }
// every script which makes player appear somewhere should change this variable ! ! !
void Awake()
{
Gateway = OnMapAppearanceMethodEnum.NewGame;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9fbd4e55be86a9d49adcb35c89ee9c18
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SaveDynamicObjects : MonoBehaviour
{
public void Save()
{
//saving player position
var player = GameObject.FindGameObjectWithTag("Player");
player.GetComponent<PlayerPosition>().SavePosition();
player.GetComponent<Player>().SaveCheckpoint();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f284f94fc82ae2b48a2fed669d33ff24
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 76fee0239f055c44882bc4e8c4b2cd4c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.SceneManagement;
[Serializable]
public class Gateway
{
[SerializeField]
public int id;
[SerializeField]
public string currentMapName;
[SerializeField]
public Vector3 coords;
[SerializeField]
public string nextMapName; //name of the next map
[SerializeField]
public Vector3 respawnCoords; // coords on the next map
public Gateway(int _id, Vector3 _coords, string _nextMapName, Vector3 _respawnCoords)
{
id = _id;
currentMapName = SceneManager.GetActiveScene().name;
coords = _coords;
respawnCoords = _respawnCoords;
nextMapName = _nextMapName;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 95981f14d41640244a6706f1444f553d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -6,35 +6,35 @@ EditorUserSettings:
serializedVersion: 4
m_ConfigSettings:
RecentlyUsedScenePath-0:
value: 22424703114646680e0b0227036c72111f19352f223d667d6d0a1532f0e1372ce7f518c8ea3f7129370bfb25
flags: 0
RecentlyUsedScenePath-1:
value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021
flags: 0
RecentlyUsedScenePath-2:
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
flags: 0
RecentlyUsedScenePath-3:
value: 22424703114646680e0b0227036c72111f19352f223d667d6d1a1226ece42776f7e93ffdfe
flags: 0
RecentlyUsedScenePath-4:
RecentlyUsedScenePath-1:
value: 22424703114646680e0b0227036c72111f19352f223d667d6d1a1827f6e93a3ff1a923e7ee2e26
flags: 0
RecentlyUsedScenePath-5:
RecentlyUsedScenePath-2:
value: 22424703114646680e0b0227036c72111f19352f223d667d6d051c3de5f5353fe7a923e7ee2e26
flags: 0
RecentlyUsedScenePath-6:
RecentlyUsedScenePath-3:
value: 22424703114646680e0b0227036c72111f19352f223d667d6d1a1827f6e93a3ff1a923e7ee2e26
flags: 0
RecentlyUsedScenePath-7:
RecentlyUsedScenePath-4:
value: 22424703114646680e0b0227036c72111f19352f223d667d6d0a123df6f23b34f1a923e7ee2e26
flags: 0
RecentlyUsedScenePath-8:
RecentlyUsedScenePath-5:
value: 22424703114646680e0b0227036c72111f19352f223d667d6d0a1532f0e1372ce7f518e8ea3f7129370bfb25
flags: 0
RecentlyUsedScenePath-9:
RecentlyUsedScenePath-6:
value: 22424703114646680e0b0227036c72111f1958072926337e38271427fb
flags: 0
RecentlyUsedScenePath-7:
value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021
flags: 0
RecentlyUsedScenePath-8:
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
flags: 0
RecentlyUsedScenePath-9:
value: 22424703114646680e0b0227036c68190c160a2e042733232867083debf42d
flags: 0
vcSharedLogLevel:
value: 0d5e400f0650
flags: 0