Added dialog system, added new scene, added player stats save

This commit is contained in:
Polarjad 2021-01-27 21:27:05 +01:00
parent 1ea616dd60
commit 232bd25285
22 changed files with 4120 additions and 683 deletions

View File

@ -10,9 +10,9 @@ GameObject:
m_Component:
- component: {fileID: 7305430595602190106}
- component: {fileID: 7305430595602190101}
- component: {fileID: 7305430595602190100}
- component: {fileID: 7305430595602190103}
- component: {fileID: -7314408697251460281}
- component: {fileID: 8941371121625508650}
m_Layer: 0
m_Name: Portal
m_TagString: Portal
@ -85,32 +85,6 @@ SpriteRenderer:
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!61 &7305430595602190100
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7305430595602190102}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 1.1875, y: 1.5}
newSize: {x: 1.1875, y: 1.5}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1.1875, y: 1.5}
m_EdgeRadius: 0
--- !u!95 &7305430595602190103
Animator:
serializedVersion: 3
@ -142,3 +116,32 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: e2c1030c00bd4a24c81a616643ec6900, type: 3}
m_Name:
m_EditorClassIdentifier:
wins: 0
highscore: 0
count: {fileID: 0}
--- !u!61 &8941371121625508650
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7305430595602190102}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: -0.031154841, y: 0.021808386}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 1.1875, y: 1.5}
newSize: {x: 1.1875, y: 1.5}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 0.93826133, y: 1.2694545}
m_EdgeRadius: 0

View File

@ -164,13 +164,13 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: ff9b8433a08e35e4fa50a029b433656c, type: 3}
m_Name:
m_EditorClassIdentifier:
speed: 3
speed: 3.5
maxHealth: 2
currentHealth: 0
enemy: {fileID: 1288833141033372906}
deathEffect: {fileID: 3474156553072057722, guid: 9f3e5c615ff914c4aa28afc0c78490da,
type: 3}
stoppingDistance: 4
stoppingDistance: 6
timer: 2
bullet: {fileID: 5467294445753478461, guid: 3e8a34909449d4b4884d06bd487dfb2d, type: 3}
text: {fileID: 0}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 63470b932abfcd242b22890a0750954d
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -682,7 +682,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.8113208, g: 0.14925243, b: 0.14925243, a: 1}
m_Color: {r: 0.9716981, g: 0.27959237, b: 0.27959237, a: 1}
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
@ -1142,6 +1142,9 @@ MonoBehaviour:
deathEffect: {fileID: 5209110736082826299, guid: 67aaa671eb02be04d9684922a07a0923,
type: 3}
playerTrigger: {fileID: 755451863}
count: {fileID: 482127932}
highscore: 0
deaths: 0
--- !u!114 &755451860
MonoBehaviour:
m_ObjectHideFlags: 0

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -0,0 +1,74 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Dialog : MonoBehaviour
{
public Text textBox;
public string[] dialogSentences;
private int index;
public GameObject continueButton;
private PlayerController controller;
public GameObject player;
public GameObject portal;
public Animator animator;
void Start()
{
player = GameObject.FindWithTag("Player");
controller = player.GetComponent<PlayerController>();
}
void Update()
{
if(textBox.text == dialogSentences[index])
{
continueButton.SetActive(true);
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
StartCoroutine(Write());
controller.enabled = false;
animator.Play("Player_Idle");
}
}
IEnumerator Write()
{
foreach(char letter in dialogSentences[index].ToCharArray())
{
textBox.text += letter;
yield return new WaitForSeconds(0.05f);
}
}
public void Continue()
{
continueButton.SetActive(false);
if (index < dialogSentences.Length - 1)
{
index++;
textBox.text = "";
StartCoroutine(Write());
}
else
{
textBox.text = "";
controller.enabled = true;
continueButton.SetActive(false);
portal.SetActive(true);
}
}
}

View File

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

View File

@ -85,4 +85,9 @@ public class EnemyFollowPlayer : MonoBehaviour
yield return new WaitForSeconds(0.1f);
}
}
void OnBecameInvisible()
{
Destroy(gameObject);
}
}

View File

@ -38,17 +38,19 @@ public class RangedEnemyAI : MonoBehaviour
if (Vector2.Distance(transform.position, target.position) < stoppingDistance)
{
transform.position = this.transform.position;
if (canShoot <= 0)
{
Instantiate(bullet, transform.position, Quaternion.identity);
canShoot = timer;
}
else
{
canShoot -= Time.deltaTime;
}
}
if(canShoot <= 0)
{
Instantiate(bullet, transform.position, Quaternion.identity);
canShoot = timer;
}
else
{
canShoot -= Time.deltaTime;
}
}
@ -101,5 +103,12 @@ public class RangedEnemyAI : MonoBehaviour
yield return new WaitForSeconds(0.1f);
}
}
void OnBecameInvisible()
{
Destroy(gameObject);
}
}

View File

@ -7,7 +7,7 @@ public class GameMenu : MonoBehaviour
{
public void PlayGame()
{
SceneManager.LoadScene("StartScene");
SceneManager.LoadScene("AgainScene");
}
public void QuitToMenu()
{

View File

@ -7,7 +7,14 @@ public class MainMenu : MonoBehaviour
{
public void PlayGame()
{
SceneManager.LoadScene("StartScene");
if (PlayerPrefs.GetInt("Deaths") == 0)
{
SceneManager.LoadScene("StartScene");
}
else
{
SceneManager.LoadScene("AgainScene");
}
}
public void QuitGame()
{

View File

@ -57,8 +57,9 @@ public class PauseMenu : MonoBehaviour
public void LoadMenu()
{
Resume();
SceneManager.LoadScene("MenuScene");
Resume();
}
public void ResumeGame()

View File

@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerStats : MonoBehaviour
{
public Text winsText;
public Text deathText;
public Text killsText;
public Text description;
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
description.GetComponent<Text>().enabled = true;
winsText.GetComponent<Text>().enabled = true;
deathText.GetComponent<Text>().enabled = true;
killsText.GetComponent<Text>().enabled = true;
winsText.text = PlayerPrefs.GetInt("Wins").ToString();
deathText.text = PlayerPrefs.GetInt("Deaths").ToString();
killsText.text = PlayerPrefs.GetInt("Kills").ToString();
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
description.GetComponent<Text>().enabled = false;
winsText.GetComponent<Text>().enabled = false;
deathText.GetComponent<Text>().enabled = false;
killsText.GetComponent<Text>().enabled = false;
}
}
}

View File

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

View File

@ -6,6 +6,18 @@ using UnityEngine.SceneManagement;
public class WinGame : MonoBehaviour
{
private GameObject[] gameObjects;
public int wins;
public int highscore;
private PlayerScore score;
public GameObject count;
void Start()
{
count = GameObject.FindGameObjectWithTag("Score");
score = count.GetComponent<PlayerScore>();
}
void Update()
{
gameObjects = GameObject.FindGameObjectsWithTag("Enemy");
@ -16,6 +28,17 @@ void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player") && gameObjects.Length == 0)
{
highscore = 0;
wins = 0;
wins++;
wins = PlayerPrefs.GetInt("Wins") + wins;
PlayerPrefs.SetInt("Wins", wins);
highscore = PlayerPrefs.GetInt("Kills") + score.killedEnemy;
PlayerPrefs.SetInt("Kills", highscore);
Debug.Log(PlayerPrefs.GetInt("Kills").ToString());
SceneManager.LoadScene("WinScene");
Debug.Log("You won!");
}

View File

@ -21,23 +21,23 @@ public class HpBar : MonoBehaviour
void Update()
{
if (health.currentHealth == 4)
if (health.currentHealth <= 4)
{
heart5.sprite = brokenHeart;
}
if (health.currentHealth == 3)
if (health.currentHealth <= 3)
{
heart4.sprite = brokenHeart;
}
if (health.currentHealth == 2)
if (health.currentHealth <= 2)
{
heart3.sprite = brokenHeart;
}
if (health.currentHealth == 1)
if (health.currentHealth <= 1)
{
heart2.sprite = brokenHeart;
}
if (health.currentHealth == 0)
if (health.currentHealth <= 0)
{
heart1.sprite = brokenHeart;
}

View File

@ -11,11 +11,18 @@ public class PlayerHealth : MonoBehaviour
public GameObject deathEffect;
private SpriteRenderer playerSprite;
public Collider2D playerTrigger;
private PlayerScore score;
public GameObject count;
public int highscore;
public int deaths;
void Start()
{
currentHealth = maxHealth;
playerSprite = this.GetComponent<SpriteRenderer>();
score = count.GetComponent<PlayerScore>();
highscore = 0;
deaths = 0;
}
void OnTriggerEnter2D(Collider2D other)
@ -52,7 +59,7 @@ public class PlayerHealth : MonoBehaviour
{
currentHealth -= 1;
Debug.Log("Health decreased");
if (currentHealth <= 0)
if (currentHealth == 0)
{
Die();
}
@ -62,6 +69,17 @@ public class PlayerHealth : MonoBehaviour
{
Instantiate(deathEffect, transform.position, Quaternion.identity);
Destroy(gameObject);
highscore = PlayerPrefs.GetInt("Kills") + score.killedEnemy;
PlayerPrefs.SetInt("Kills", highscore);
Debug.Log(PlayerPrefs.GetInt("Kills").ToString());
deaths++;
deaths = PlayerPrefs.GetInt("Deaths") + deaths;
PlayerPrefs.SetInt("Deaths", deaths);
Debug.Log(PlayerPrefs.GetInt("Deaths").ToString());
SceneManager.LoadScene("GameOver");
}
}

BIN
Assets/Sprites/Board.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

View File

@ -0,0 +1,152 @@
fileFormatVersion: 2
guid: fb4ae6d888eef8745922ccceadaccee4
TextureImporter:
internalIDToNameTable:
- first:
213: 7841750413799554831
second: Board_0
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 0
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 2
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 16
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 2
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 2
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 2
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 2
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites:
- serializedVersion: 2
name: Board_0
rect:
serializedVersion: 2
x: 7
y: 7
width: 17
height: 14
alignment: 0
pivot: {x: 0, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: f0f7bc7347e73dc60800000000000000
internalID: 7841750413799554831
vertices: []
indices:
edges: []
weights: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -20,4 +20,7 @@ EditorBuildSettings:
- enabled: 1
path: Assets/Scenes/WinScene.unity
guid: 03432555cb0e04a45bdf2456d296b553
- enabled: 1
path: Assets/Scenes/AgainScene.unity
guid: 63470b932abfcd242b22890a0750954d
m_configObjects: {}