init
This commit is contained in:
commit
78b901484a
323 changed files with 109774 additions and 0 deletions
61
Assets/Scripts/AudioManager.cs
Normal file
61
Assets/Scripts/AudioManager.cs
Normal file
|
@ -0,0 +1,61 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
public class AudioManager : MonoBehaviour{
|
||||
|
||||
[SerializeField] Sound[] sounds;
|
||||
|
||||
public static AudioManager instance;
|
||||
|
||||
void Awake(){
|
||||
if(instance == null){
|
||||
instance = this;
|
||||
}else{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
foreach (Sound s in sounds){
|
||||
s.source = gameObject.AddComponent<AudioSource>();
|
||||
s.source.clip = s.clip;
|
||||
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
s.source.loop = s.loop;
|
||||
}
|
||||
}
|
||||
|
||||
public void Play(string name, bool randomPitch){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (randomPitch){
|
||||
s.source.volume = s.volume * (1f + UnityEngine.Random.Range(-s.volumeVariance / 2f, s.volumeVariance / 2f));
|
||||
s.source.pitch = s.pitch * (1f + UnityEngine.Random.Range(-s.pitchVariance / 2f, s.pitchVariance / 2f));
|
||||
}
|
||||
|
||||
s.source.Play();
|
||||
}
|
||||
|
||||
public void PlayOneShot(string name, bool randomPitch){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (randomPitch){
|
||||
s.source.volume = s.volume * (1f + UnityEngine.Random.Range(-s.volumeVariance / 2f, s.volumeVariance / 2f));
|
||||
s.source.pitch = s.pitch * (1f + UnityEngine.Random.Range(-s.pitchVariance / 2f, s.pitchVariance / 2f));
|
||||
}
|
||||
|
||||
s.source.PlayOneShot(s.clip);
|
||||
}
|
||||
}
|
11
Assets/Scripts/AudioManager.cs.meta
Normal file
11
Assets/Scripts/AudioManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3bcf58dbe898c484f98222828e17f44c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Enemies.meta
Normal file
8
Assets/Scripts/Enemies.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 91a549c674fb17049b5772dd90599e8b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
203
Assets/Scripts/Enemies/BishopController.cs
Normal file
203
Assets/Scripts/Enemies/BishopController.cs
Normal file
|
@ -0,0 +1,203 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BishopController : MonoBehaviour, IPooledObject{
|
||||
|
||||
[Range(1, 5)] [SerializeField] int framesToMove = 1;
|
||||
int currentFrame = 1;
|
||||
bool moving;
|
||||
|
||||
[Space]
|
||||
[Range(0, .3f)] [SerializeField] float movementSmoothingTime = .1f;
|
||||
[SerializeField] float maxDistance;
|
||||
|
||||
[Space]
|
||||
[SerializeField] LayerMask whatIsEnemy;
|
||||
|
||||
Vector3[] possibleRightPositions;
|
||||
Vector3[] possibleLeftPositions;
|
||||
Vector3[] possibleForwardPositions;
|
||||
Vector3[] possibleBackPositions;
|
||||
|
||||
Vector3[] availablePositions;
|
||||
public Vector3 positionToGo;
|
||||
Vector3 currentPosition;
|
||||
Vector3 velocity;
|
||||
|
||||
Transform player;
|
||||
|
||||
void Awake(){
|
||||
player = FindObjectOfType<PlayerController>().transform;
|
||||
FindObjectOfType<PlayerController>().onMove.AddListener(() => Move());
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
public void OnObjectSpawn(){
|
||||
moving = false;
|
||||
positionToGo = currentPosition = transform.position;
|
||||
currentFrame = 1;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > .1f){
|
||||
transform.position = Vector3.SmoothDamp(transform.position, positionToGo, ref velocity, movementSmoothingTime);
|
||||
}else if (Vector3.Distance(transform.position, positionToGo) < .1f){
|
||||
transform.position = positionToGo;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
if (!Application.isPlaying){
|
||||
Gizmos.DrawLine(transform.position, transform.position + new Vector3(1, 0, 1) * maxDistance);
|
||||
Gizmos.DrawLine(transform.position, transform.position + new Vector3(-1, 0, 1) * maxDistance);
|
||||
Gizmos.DrawLine(transform.position, transform.position + new Vector3(1, 0, -1) * maxDistance);
|
||||
Gizmos.DrawLine(transform.position, transform.position + new Vector3(-1, 0, -1) * maxDistance);
|
||||
|
||||
Gizmos.color = Color.magenta;
|
||||
for (float i = 0; i <= maxDistance; i += 1.25f){
|
||||
if (i != 0){
|
||||
Gizmos.DrawSphere(transform.position + new Vector3(1, 0, 1) * i, .15f);
|
||||
Gizmos.DrawSphere(transform.position + new Vector3(-1, 0, 1) * i, .15f);
|
||||
Gizmos.DrawSphere(transform.position + new Vector3(1, 0, -1) * i, .15f);
|
||||
Gizmos.DrawSphere(transform.position + new Vector3(-1, 0, -1) * i, .15f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Move(){
|
||||
if (currentFrame < framesToMove){
|
||||
currentFrame++;
|
||||
moving = false;
|
||||
return;
|
||||
}
|
||||
currentFrame = 1;
|
||||
moving = true;
|
||||
if (gameObject.activeSelf){
|
||||
StartCoroutine(ResetMoving());
|
||||
}
|
||||
|
||||
currentPosition = positionToGo;
|
||||
|
||||
possibleRightPositions = new Vector3[6];
|
||||
possibleLeftPositions = new Vector3[6];
|
||||
possibleForwardPositions = new Vector3[6];
|
||||
possibleBackPositions = new Vector3[6];
|
||||
int currentRound = 1;
|
||||
|
||||
for (float i = 0; i <= maxDistance; i += 1.25f){
|
||||
if (i != 0){
|
||||
possibleRightPositions[currentRound - 1] = currentPosition + new Vector3(1, 0, 1) * i;
|
||||
possibleLeftPositions[currentRound - 1] = currentPosition + new Vector3(-1, 0, 1) * i;
|
||||
possibleForwardPositions[currentRound - 1] = currentPosition + new Vector3(1, 0, -1) * i;
|
||||
possibleBackPositions[currentRound - 1] = currentPosition + new Vector3(-1, 0, -1) * i;
|
||||
currentRound++;
|
||||
}
|
||||
}
|
||||
availablePositions = new Vector3[24];
|
||||
//Right
|
||||
for (int i = 0; i < possibleRightPositions.Length - 1; i++){
|
||||
if (Physics.CheckSphere(possibleRightPositions[i], .3f, whatIsEnemy)){
|
||||
break;
|
||||
}else{
|
||||
availablePositions[i] = possibleRightPositions[i];
|
||||
}
|
||||
}
|
||||
|
||||
//Left
|
||||
for (int i = 0; i < possibleLeftPositions.Length - 1; i++){
|
||||
if (Physics.CheckSphere(possibleLeftPositions[i], .3f, whatIsEnemy)){
|
||||
break;
|
||||
}else{
|
||||
availablePositions[i + 5] = possibleLeftPositions[i];
|
||||
}
|
||||
}
|
||||
|
||||
//Forward
|
||||
for (int i = 0; i < possibleForwardPositions.Length - 1; i++){
|
||||
if (Physics.CheckSphere(possibleForwardPositions[i], .3f, whatIsEnemy)){
|
||||
break;
|
||||
}else{
|
||||
availablePositions[i + 11] = possibleForwardPositions[i];
|
||||
}
|
||||
}
|
||||
|
||||
//Back
|
||||
for (int i = 0; i < possibleBackPositions.Length - 1; i++){
|
||||
if (Physics.CheckSphere(possibleBackPositions[i], .3f, whatIsEnemy)){
|
||||
break;
|
||||
}else{
|
||||
availablePositions[i + 17] = possibleBackPositions[i];
|
||||
}
|
||||
}
|
||||
|
||||
float nearestDist = float.MaxValue;
|
||||
Vector3 nearestPos = new Vector3();
|
||||
foreach (Vector3 v in availablePositions){
|
||||
if (v != Vector3.zero){
|
||||
float dist = Vector3.Distance(v, player.position);
|
||||
if (dist < nearestDist){
|
||||
nearestDist = dist;
|
||||
nearestPos = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
positionToGo = (nearestPos == Vector3.zero) ? currentPosition : nearestPos;
|
||||
}
|
||||
|
||||
IEnumerator ResetMoving(){
|
||||
yield return new WaitForSeconds(movementSmoothingTime * 3);
|
||||
moving = false;
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider col){
|
||||
if (col.CompareTag("Limits")){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision col){
|
||||
if (col.gameObject.layer == Mathf.RoundToInt(Mathf.Log(whatIsEnemy.value, 2))){
|
||||
BishopController bishop = col.gameObject.GetComponent<BishopController>();
|
||||
KnightController knight = col.gameObject.GetComponent<KnightController>();
|
||||
PawnController pawn = col.gameObject.GetComponent<PawnController>();
|
||||
RookController rook = col.gameObject.GetComponent<RookController>();
|
||||
if (bishop != null){
|
||||
if (bishop.positionToGo == positionToGo){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > Vector3.Distance(col.transform.position, bishop.positionToGo)){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}else if (knight != null){
|
||||
if (knight.positionToGo == positionToGo){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > Vector3.Distance(col.transform.position, knight.positionToGo)){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}else if (pawn != null){
|
||||
if (pawn.positionToGo == positionToGo){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > Vector3.Distance(col.transform.position, pawn.positionToGo)){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}else if (rook != null){
|
||||
if (rook.positionToGo == positionToGo){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > Vector3.Distance(col.transform.position, rook.positionToGo)){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (col.gameObject.tag == "Player"){
|
||||
PlayerController player = col.gameObject.GetComponent<PlayerController>();
|
||||
if (player.positionToGo == positionToGo && moving){
|
||||
player.Damage();
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Enemies/BishopController.cs.meta
Normal file
11
Assets/Scripts/Enemies/BishopController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c06988803bc7e7943b3ed6296907d884
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
146
Assets/Scripts/Enemies/KnightController.cs
Normal file
146
Assets/Scripts/Enemies/KnightController.cs
Normal file
|
@ -0,0 +1,146 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class KnightController : MonoBehaviour, IPooledObject{
|
||||
|
||||
[Range(1, 5)] [SerializeField] int framesToMove = 1;
|
||||
int currentFrame = 1;
|
||||
bool moving;
|
||||
|
||||
[Space]
|
||||
[Range(0, .3f)] [SerializeField] float movementSmoothingTime = .1f;
|
||||
[SerializeField] Vector3[] possiblePositions;
|
||||
[SerializeField] LayerMask whatIsEnemy;
|
||||
|
||||
Vector3[] availablePositions;
|
||||
public Vector3 positionToGo;
|
||||
Vector3 currentPosition;
|
||||
Vector3 velocity;
|
||||
|
||||
Transform player;
|
||||
|
||||
void Awake(){
|
||||
player = FindObjectOfType<PlayerController>().transform;
|
||||
FindObjectOfType<PlayerController>().onMove.AddListener(() => Move());
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
public void OnObjectSpawn(){
|
||||
moving = false;
|
||||
positionToGo = currentPosition = transform.position;
|
||||
currentFrame = 1;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > .1f){
|
||||
transform.position = Vector3.SmoothDamp(transform.position, positionToGo, ref velocity, movementSmoothingTime);
|
||||
}else if (Vector3.Distance(transform.position, positionToGo) < .1f){
|
||||
transform.position = positionToGo;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
if (!Application.isPlaying){
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawSphere(transform.position + possiblePositions[0], .15f);
|
||||
Gizmos.DrawSphere(transform.position + possiblePositions[1], .15f);
|
||||
Gizmos.DrawSphere(transform.position + possiblePositions[2], .15f);
|
||||
Gizmos.DrawSphere(transform.position + possiblePositions[3], .15f);
|
||||
Gizmos.DrawSphere(transform.position + possiblePositions[4], .15f);
|
||||
Gizmos.DrawSphere(transform.position + possiblePositions[5], .15f);
|
||||
Gizmos.DrawSphere(transform.position + possiblePositions[6], .15f);
|
||||
Gizmos.DrawSphere(transform.position + possiblePositions[7], .15f);
|
||||
}
|
||||
}
|
||||
|
||||
void Move(){
|
||||
if (currentFrame < framesToMove){
|
||||
currentFrame++;
|
||||
moving = false;
|
||||
return;
|
||||
}
|
||||
currentFrame = 1;
|
||||
moving = true;
|
||||
if (gameObject.activeSelf){
|
||||
StartCoroutine(ResetMoving());
|
||||
}
|
||||
|
||||
currentPosition = positionToGo;
|
||||
|
||||
availablePositions = new Vector3[8];
|
||||
for (int i = 0; i < availablePositions.Length - 1; i++){
|
||||
if (!Physics.CheckSphere(currentPosition + possiblePositions[i], .3f, whatIsEnemy)){
|
||||
availablePositions[i] = (currentPosition + possiblePositions[i]);
|
||||
}
|
||||
}
|
||||
|
||||
float nearestDist = float.MaxValue;
|
||||
Vector3 nearestPos = new Vector3();
|
||||
foreach (Vector3 v in availablePositions){
|
||||
if (v != Vector3.zero){
|
||||
float dist = Vector3.Distance(v, player.position);
|
||||
if (dist < nearestDist){
|
||||
nearestDist = dist;
|
||||
nearestPos = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
positionToGo = (nearestPos == Vector3.zero) ? currentPosition : nearestPos;
|
||||
}
|
||||
|
||||
IEnumerator ResetMoving(){
|
||||
yield return new WaitForSeconds(movementSmoothingTime * 3);
|
||||
moving = false;
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider col){
|
||||
if (col.CompareTag("Limits")){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision col){
|
||||
if (col.gameObject.layer == Mathf.RoundToInt(Mathf.Log(whatIsEnemy.value, 2))){
|
||||
BishopController bishop = col.gameObject.GetComponent<BishopController>();
|
||||
KnightController knight = col.gameObject.GetComponent<KnightController>();
|
||||
PawnController pawn = col.gameObject.GetComponent<PawnController>();
|
||||
RookController rook = col.gameObject.GetComponent<RookController>();
|
||||
if (bishop != null){
|
||||
if (bishop.positionToGo == positionToGo){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > Vector3.Distance(col.transform.position, bishop.positionToGo)){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}else if (knight != null){
|
||||
if (knight.positionToGo == positionToGo){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > Vector3.Distance(col.transform.position, knight.positionToGo)){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}else if (pawn != null){
|
||||
if (pawn.positionToGo == positionToGo){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > Vector3.Distance(col.transform.position, pawn.positionToGo)){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}else if (rook != null){
|
||||
if (rook.positionToGo == positionToGo){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > Vector3.Distance(col.transform.position, rook.positionToGo)){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (col.gameObject.tag == "Player"){
|
||||
PlayerController player = col.gameObject.GetComponent<PlayerController>();
|
||||
if (player.positionToGo == positionToGo && moving){
|
||||
player.Damage();
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Enemies/KnightController.cs.meta
Normal file
11
Assets/Scripts/Enemies/KnightController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5e9887dfcf4762649bfb42b18870d5a4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
182
Assets/Scripts/Enemies/PawnController.cs
Normal file
182
Assets/Scripts/Enemies/PawnController.cs
Normal file
|
@ -0,0 +1,182 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PawnController : MonoBehaviour, IPooledObject{
|
||||
|
||||
[Range(1, 5)] [SerializeField] int framesToMove = 1;
|
||||
int currentFrame = 1;
|
||||
bool moving;
|
||||
|
||||
[Space]
|
||||
[Range(0, .3f)] [SerializeField] float movementSmoothingTime = .1f;
|
||||
[SerializeField] LayerMask whatIsEnemy;
|
||||
[SerializeField] LayerMask whatIsPlayer;
|
||||
|
||||
Vector3[] possiblePositions;
|
||||
Vector3[] availablePositions;
|
||||
Vector3 playerKillPosition;
|
||||
public Vector3 positionToGo;
|
||||
Vector3 currentPosition;
|
||||
Vector3 velocity;
|
||||
|
||||
Transform player;
|
||||
|
||||
void Awake(){
|
||||
player = FindObjectOfType<PlayerController>().transform;
|
||||
FindObjectOfType<PlayerController>().onMove.AddListener(() => Move());
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
public void OnObjectSpawn(){
|
||||
positionToGo = currentPosition = transform.position;
|
||||
currentFrame = 1;
|
||||
moving = false;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > .1f){
|
||||
transform.position = Vector3.SmoothDamp(transform.position, positionToGo, ref velocity, movementSmoothingTime);
|
||||
}else if (Vector3.Distance(transform.position, positionToGo) < .1f){
|
||||
transform.position = positionToGo;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
if (!Application.isPlaying){
|
||||
Gizmos.color = Color.cyan;
|
||||
Gizmos.DrawSphere(transform.position + Vector3.right * 1.25f, .15f);
|
||||
Gizmos.DrawSphere(transform.position + Vector3.left * 1.25f, .15f);
|
||||
Gizmos.DrawSphere(transform.position + Vector3.forward * 1.25f, .15f);
|
||||
Gizmos.DrawSphere(transform.position + Vector3.back * 1.25f, .15f);
|
||||
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireSphere(transform.position + new Vector3(1.25f, 0, 1.25f), .3f);
|
||||
Gizmos.DrawWireSphere(transform.position + new Vector3(-1.25f, 0, 1.25f), .3f);
|
||||
Gizmos.DrawWireSphere(transform.position + new Vector3(1.25f, 0, -1.25f), .3f);
|
||||
Gizmos.DrawWireSphere(transform.position + new Vector3(-1.25f, 0, -1.25f), .3f);
|
||||
}
|
||||
}
|
||||
|
||||
void Move(){
|
||||
if(currentFrame < framesToMove){
|
||||
currentFrame++;
|
||||
moving = false;
|
||||
return;
|
||||
}
|
||||
currentFrame = 1;
|
||||
moving = true;
|
||||
if (gameObject.activeSelf){
|
||||
StartCoroutine(ResetMoving());
|
||||
}
|
||||
|
||||
currentPosition = positionToGo;
|
||||
|
||||
possiblePositions = new Vector3[4];
|
||||
possiblePositions[0] = currentPosition + Vector3.right * 1.25f;
|
||||
possiblePositions[1] = currentPosition + Vector3.left * 1.25f;
|
||||
possiblePositions[2] = currentPosition + Vector3.forward * 1.25f;
|
||||
possiblePositions[3] = currentPosition + Vector3.back * 1.25f;
|
||||
|
||||
availablePositions = new Vector3[4];
|
||||
if(!Physics.CheckSphere(possiblePositions[0], .3f, whatIsEnemy) && !Physics.CheckSphere(possiblePositions[0], .3f, whatIsPlayer)){
|
||||
availablePositions[0] = possiblePositions[0];
|
||||
}
|
||||
if (!Physics.CheckSphere(possiblePositions[0], .3f, whatIsEnemy) && !Physics.CheckSphere(possiblePositions[0], .3f, whatIsPlayer)){
|
||||
availablePositions[1] = possiblePositions[1];
|
||||
}
|
||||
if (!Physics.CheckSphere(possiblePositions[0], .3f, whatIsEnemy) && !Physics.CheckSphere(possiblePositions[0], .3f, whatIsPlayer)){
|
||||
availablePositions[2] = possiblePositions[2];
|
||||
}
|
||||
if (!Physics.CheckSphere(possiblePositions[0], .3f, whatIsEnemy) && !Physics.CheckSphere(possiblePositions[0], .3f, whatIsPlayer)){
|
||||
availablePositions[3] = possiblePositions[3];
|
||||
}
|
||||
|
||||
if (Physics.CheckSphere(currentPosition + new Vector3(1.25f, 0, 1.25f), .3f, whatIsPlayer)){
|
||||
playerKillPosition = currentPosition + new Vector3(1.25f, 0, 1.25f);
|
||||
}
|
||||
if (Physics.CheckSphere(currentPosition + new Vector3(-1.25f, 0, 1.25f), .3f, whatIsPlayer)){
|
||||
playerKillPosition = currentPosition + new Vector3(-1.25f, 0, 1.25f);
|
||||
}
|
||||
if (Physics.CheckSphere(currentPosition + new Vector3(1.25f, 0, -1.25f), .3f, whatIsPlayer)){
|
||||
playerKillPosition = currentPosition + new Vector3(1.25f, 0, -1.25f);
|
||||
}
|
||||
if (Physics.CheckSphere(currentPosition + new Vector3(-1.25f, 0, -1.25f), .3f, whatIsPlayer)){
|
||||
playerKillPosition = currentPosition + new Vector3(-1.25f, 0, -1.25f);
|
||||
}
|
||||
|
||||
if(playerKillPosition == Vector3.zero){
|
||||
float nearestDist = float.MaxValue;
|
||||
Vector3 nearestPos = new Vector3();
|
||||
|
||||
foreach (Vector3 v in availablePositions){
|
||||
if (v != Vector3.zero){
|
||||
float dist = Vector3.Distance(v, player.position);
|
||||
if (dist < nearestDist){
|
||||
nearestDist = dist;
|
||||
nearestPos = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
positionToGo = (nearestPos == Vector3.zero) ? currentPosition : nearestPos;
|
||||
}else{
|
||||
positionToGo = playerKillPosition;
|
||||
playerKillPosition = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator ResetMoving(){
|
||||
yield return new WaitForSeconds(movementSmoothingTime * 3);
|
||||
moving = false;
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider col){
|
||||
if (col.CompareTag("Limits")){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision col){
|
||||
if (col.gameObject.layer == Mathf.RoundToInt(Mathf.Log(whatIsEnemy.value, 2))){
|
||||
BishopController bishop = col.gameObject.GetComponent<BishopController>();
|
||||
KnightController knight = col.gameObject.GetComponent<KnightController>();
|
||||
PawnController pawn = col.gameObject.GetComponent<PawnController>();
|
||||
RookController rook = col.gameObject.GetComponent<RookController>();
|
||||
if (bishop != null){
|
||||
if (bishop.positionToGo == positionToGo){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > Vector3.Distance(col.transform.position, bishop.positionToGo)){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}else if (knight != null){
|
||||
if (knight.positionToGo == positionToGo){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > Vector3.Distance(col.transform.position, knight.positionToGo)){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}else if (pawn != null){
|
||||
if (pawn.positionToGo == positionToGo){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > Vector3.Distance(col.transform.position, pawn.positionToGo)){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}else if (rook != null){
|
||||
if (rook.positionToGo == positionToGo){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > Vector3.Distance(col.transform.position, rook.positionToGo)){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (col.gameObject.tag == "Player"){
|
||||
PlayerController player = col.gameObject.GetComponent<PlayerController>();
|
||||
if(player.positionToGo == positionToGo && moving){
|
||||
player.Damage();
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Enemies/PawnController.cs.meta
Normal file
11
Assets/Scripts/Enemies/PawnController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 23b57acca63bfe24889190c33026461b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
204
Assets/Scripts/Enemies/RookController.cs
Normal file
204
Assets/Scripts/Enemies/RookController.cs
Normal file
|
@ -0,0 +1,204 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class RookController : MonoBehaviour, IPooledObject{
|
||||
|
||||
[Range(1, 5)] [SerializeField] int framesToMove = 1;
|
||||
int currentFrame = 1;
|
||||
bool moving;
|
||||
|
||||
[Space]
|
||||
[Range(0, .3f)] [SerializeField] float movementSmoothingTime = .1f;
|
||||
[SerializeField] float maxDistance;
|
||||
|
||||
[Space]
|
||||
[SerializeField] LayerMask whatIsEnemy;
|
||||
|
||||
Vector3[] possibleRightPositions;
|
||||
Vector3[] possibleLeftPositions;
|
||||
Vector3[] possibleForwardPositions;
|
||||
Vector3[] possibleBackPositions;
|
||||
|
||||
Vector3[] availablePositions;
|
||||
public Vector3 positionToGo;
|
||||
Vector3 currentPosition;
|
||||
Vector3 velocity;
|
||||
|
||||
Transform player;
|
||||
|
||||
void Awake(){
|
||||
player = FindObjectOfType<PlayerController>().transform;
|
||||
FindObjectOfType<PlayerController>().onMove.AddListener(() => Move());
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
public void OnObjectSpawn(){
|
||||
moving = false;
|
||||
positionToGo = currentPosition = transform.position;
|
||||
currentFrame = 1;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > .1f){
|
||||
transform.position = Vector3.SmoothDamp(transform.position, positionToGo, ref velocity, movementSmoothingTime);
|
||||
}else if (Vector3.Distance(transform.position, positionToGo) < .1f){
|
||||
transform.position = positionToGo;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
if (!Application.isPlaying){
|
||||
Gizmos.DrawLine(transform.position, transform.position + Vector3.right * maxDistance);
|
||||
Gizmos.DrawLine(transform.position, transform.position + Vector3.left * maxDistance);
|
||||
Gizmos.DrawLine(transform.position, transform.position + Vector3.forward * maxDistance);
|
||||
Gizmos.DrawLine(transform.position, transform.position + Vector3.back * maxDistance);
|
||||
|
||||
Gizmos.color = Color.yellow;
|
||||
for (float i = 0; i <= maxDistance; i += 1.25f){
|
||||
if (i != 0){
|
||||
Gizmos.DrawSphere(transform.position + Vector3.right * i, .15f);
|
||||
Gizmos.DrawSphere(transform.position + Vector3.left * i, .15f);
|
||||
Gizmos.DrawSphere(transform.position + Vector3.forward * i, .15f);
|
||||
Gizmos.DrawSphere(transform.position + Vector3.back * i, .15f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Move(){
|
||||
if (currentFrame < framesToMove){
|
||||
currentFrame++;
|
||||
moving = false;
|
||||
return;
|
||||
}
|
||||
moving = true;
|
||||
if (gameObject.activeSelf){
|
||||
StartCoroutine(ResetMoving());
|
||||
}
|
||||
|
||||
currentFrame = 1;
|
||||
|
||||
currentPosition = positionToGo;
|
||||
|
||||
possibleRightPositions = new Vector3[6];
|
||||
possibleLeftPositions = new Vector3[6];
|
||||
possibleForwardPositions = new Vector3[6];
|
||||
possibleBackPositions = new Vector3[6];
|
||||
int currentRound = 1;
|
||||
|
||||
for (float i = 0; i <= maxDistance; i += 1.25f){
|
||||
if(i != 0){
|
||||
possibleRightPositions[currentRound - 1] = currentPosition + Vector3.right * i;
|
||||
possibleLeftPositions[currentRound - 1] = currentPosition + Vector3.left * i;
|
||||
possibleForwardPositions[currentRound - 1] = currentPosition + Vector3.forward * i;
|
||||
possibleBackPositions[currentRound - 1] = currentPosition + Vector3.back * i;
|
||||
currentRound++;
|
||||
}
|
||||
}
|
||||
availablePositions = new Vector3[24];
|
||||
//Right
|
||||
for (int i = 0; i < possibleRightPositions.Length - 1; i++){
|
||||
if (Physics.CheckSphere(possibleRightPositions[i], .3f, whatIsEnemy)){
|
||||
break;
|
||||
}else{
|
||||
availablePositions[i] = possibleRightPositions[i];
|
||||
}
|
||||
}
|
||||
|
||||
//Left
|
||||
for (int i = 0; i < possibleLeftPositions.Length - 1; i++){
|
||||
if (Physics.CheckSphere(possibleLeftPositions[i], .3f, whatIsEnemy)){
|
||||
break;
|
||||
}else{
|
||||
availablePositions[i + 5] = possibleLeftPositions[i];
|
||||
}
|
||||
}
|
||||
|
||||
//Forward
|
||||
for (int i = 0; i < possibleForwardPositions.Length - 1; i++){
|
||||
if (Physics.CheckSphere(possibleForwardPositions[i], .3f, whatIsEnemy)){
|
||||
break;
|
||||
}else{
|
||||
availablePositions[i + 11] = possibleForwardPositions[i];
|
||||
}
|
||||
}
|
||||
|
||||
//Back
|
||||
for (int i = 0; i < possibleBackPositions.Length - 1; i++){
|
||||
if (Physics.CheckSphere(possibleBackPositions[i], .3f, whatIsEnemy)){
|
||||
break;
|
||||
}else{
|
||||
availablePositions[i + 17] = possibleBackPositions[i];
|
||||
}
|
||||
}
|
||||
|
||||
float nearestDist = float.MaxValue;
|
||||
Vector3 nearestPos = new Vector3();
|
||||
foreach (Vector3 v in availablePositions){
|
||||
if (v != Vector3.zero){
|
||||
float dist = Vector3.Distance(v, player.position);
|
||||
if (dist < nearestDist){
|
||||
nearestDist = dist;
|
||||
nearestPos = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
positionToGo = (nearestPos == Vector3.zero) ? currentPosition : nearestPos;
|
||||
}
|
||||
|
||||
IEnumerator ResetMoving(){
|
||||
yield return new WaitForSeconds(movementSmoothingTime * 3);
|
||||
moving = false;
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider col){
|
||||
if (col.CompareTag("Limits")){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision col){
|
||||
if (col.gameObject.layer == Mathf.RoundToInt(Mathf.Log(whatIsEnemy.value, 2))){
|
||||
BishopController bishop = col.gameObject.GetComponent<BishopController>();
|
||||
KnightController knight = col.gameObject.GetComponent<KnightController>();
|
||||
PawnController pawn = col.gameObject.GetComponent<PawnController>();
|
||||
RookController rook = col.gameObject.GetComponent<RookController>();
|
||||
if (bishop != null){
|
||||
if(bishop.positionToGo == positionToGo){
|
||||
if(Vector3.Distance(transform.position, positionToGo) > Vector3.Distance(col.transform.position, bishop.positionToGo)){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}else if(knight != null){
|
||||
if (knight.positionToGo == positionToGo){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > Vector3.Distance(col.transform.position, knight.positionToGo)){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}else if(pawn != null){
|
||||
if (pawn.positionToGo == positionToGo){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > Vector3.Distance(col.transform.position, pawn.positionToGo)){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}else if(rook != null){
|
||||
if (rook.positionToGo == positionToGo){
|
||||
if (Vector3.Distance(transform.position, positionToGo) > Vector3.Distance(col.transform.position, rook.positionToGo)){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(col.gameObject.tag == "Player"){
|
||||
PlayerController player = col.gameObject.GetComponent<PlayerController>();
|
||||
if (player.positionToGo == positionToGo && moving){
|
||||
player.Damage();
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Enemies/RookController.cs.meta
Normal file
11
Assets/Scripts/Enemies/RookController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6015b88237bd16f4ab1a6dd2216c8f6f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
54
Assets/Scripts/GameOverCanvas.cs
Normal file
54
Assets/Scripts/GameOverCanvas.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameOverCanvas : MonoBehaviour{
|
||||
|
||||
[SerializeField] TextMeshProUGUI newRecordText;
|
||||
|
||||
[Space]
|
||||
public int movementsDone;
|
||||
[SerializeField] TextMeshProUGUI movementDonePoints;
|
||||
|
||||
[Space]
|
||||
public int enemiesKilled;
|
||||
[SerializeField] TextMeshProUGUI enemiesKilledPoints;
|
||||
|
||||
[Space]
|
||||
[SerializeField] int totalPoints;
|
||||
[SerializeField] TextMeshProUGUI totalPointsPoints;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
totalPoints = (movementsDone / 3) * enemiesKilled;
|
||||
totalPointsPoints.text = totalPoints.ToString();
|
||||
movementDonePoints.text = movementsDone.ToString();
|
||||
enemiesKilledPoints.text = enemiesKilled.ToString();
|
||||
|
||||
if (PlayerPrefs.HasKey("MaxScore")){
|
||||
if(PlayerPrefs.GetInt("MaxScore") < totalPoints){
|
||||
newRecordText.enabled = true;
|
||||
PlayerPrefs.SetInt("MaxScore", totalPoints);
|
||||
}else{
|
||||
newRecordText.enabled = false;
|
||||
}
|
||||
}else{
|
||||
newRecordText.enabled = true;
|
||||
PlayerPrefs.SetInt("MaxScore", totalPoints);
|
||||
}
|
||||
}
|
||||
|
||||
public void Menu(){
|
||||
SceneLoader.instance.LoadScene(0, SceneLoader.DifficultySelected.Easy);
|
||||
}
|
||||
|
||||
public void Retry(){
|
||||
CanvasManager canvas = FindObjectOfType<CanvasManager>();
|
||||
if(canvas.difficulty == CanvasManager.CanvasDifficulty.Easy){
|
||||
SceneLoader.instance.LoadScene(1, SceneLoader.DifficultySelected.Easy);
|
||||
}else{
|
||||
SceneLoader.instance.LoadScene(1, SceneLoader.DifficultySelected.Hard);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/GameOverCanvas.cs.meta
Normal file
11
Assets/Scripts/GameOverCanvas.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f8d8aeddca824bc4698bf5fdfb87e25a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Managers.meta
Normal file
8
Assets/Scripts/Managers.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b8fab2f4c8b379d449373d20797c75d1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
3
Assets/Scripts/Managers/IPooledObject.cs
Normal file
3
Assets/Scripts/Managers/IPooledObject.cs
Normal file
|
@ -0,0 +1,3 @@
|
|||
public interface IPooledObject{
|
||||
void OnObjectSpawn();
|
||||
}
|
11
Assets/Scripts/Managers/IPooledObject.cs.meta
Normal file
11
Assets/Scripts/Managers/IPooledObject.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 29bcf1e7786d2d84882a1099b157f127
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
58
Assets/Scripts/Managers/ObjectPooler.cs
Normal file
58
Assets/Scripts/Managers/ObjectPooler.cs
Normal file
|
@ -0,0 +1,58 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ObjectPooler : MonoBehaviour{
|
||||
|
||||
[System.Serializable]
|
||||
public class Pool{
|
||||
public string tag;
|
||||
public GameObject prefab;
|
||||
public int size;
|
||||
}
|
||||
|
||||
[SerializeField] List<Pool> pools;
|
||||
[SerializeField] Dictionary<string, Queue<GameObject>> poolDictionary;
|
||||
|
||||
public static ObjectPooler instance;
|
||||
|
||||
void Awake(){
|
||||
instance = this;
|
||||
|
||||
poolDictionary = new Dictionary<string, Queue<GameObject>>();
|
||||
|
||||
foreach (Pool pool in pools){
|
||||
Queue<GameObject> objectPool = new Queue<GameObject>();
|
||||
|
||||
for (int i = 0; i < pool.size; i++){
|
||||
GameObject obj = Instantiate(pool.prefab, transform);
|
||||
obj.SetActive(false);
|
||||
objectPool.Enqueue(obj);
|
||||
}
|
||||
|
||||
poolDictionary.Add(pool.tag, objectPool);
|
||||
}
|
||||
}
|
||||
|
||||
public GameObject SpawnFromPool(string tag, Vector3 position, Quaternion rotation){
|
||||
if (!poolDictionary.ContainsKey(tag)){
|
||||
Debug.LogWarning("Pool with tag " + tag + " doesn't exist.");
|
||||
return null;
|
||||
}
|
||||
|
||||
GameObject objectToSpawn = poolDictionary[tag].Dequeue();
|
||||
|
||||
objectToSpawn.SetActive(true);
|
||||
objectToSpawn.transform.position = position;
|
||||
objectToSpawn.transform.rotation = rotation;
|
||||
|
||||
IPooledObject pooledObj = objectToSpawn.GetComponent<IPooledObject>();
|
||||
if(pooledObj != null){
|
||||
pooledObj.OnObjectSpawn();
|
||||
}
|
||||
|
||||
poolDictionary[tag].Enqueue(objectToSpawn);
|
||||
|
||||
return objectToSpawn;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Managers/ObjectPooler.cs.meta
Normal file
11
Assets/Scripts/Managers/ObjectPooler.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: aed773e06e153e243972de36c1a5e75a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
10
Assets/Scripts/PlaySound.cs
Normal file
10
Assets/Scripts/PlaySound.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlaySound : MonoBehaviour{
|
||||
|
||||
public void Play(string sound){
|
||||
AudioManager.instance.Play(sound, true);
|
||||
}
|
||||
}
|
11
Assets/Scripts/PlaySound.cs.meta
Normal file
11
Assets/Scripts/PlaySound.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f8cbfd3e619858b48814dcd16e3e14ae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
399
Assets/Scripts/PlayerController.cs
Normal file
399
Assets/Scripts/PlayerController.cs
Normal file
|
@ -0,0 +1,399 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
[System.Serializable] public class Move : UnityEvent { }
|
||||
|
||||
public class PlayerController : MonoBehaviour{
|
||||
|
||||
[SerializeField] GameObject deathParticles;
|
||||
[SerializeField] GameObject visualContainer;
|
||||
bool dead;
|
||||
[HideInInspector] public Move onMove;
|
||||
bool canMove = true;
|
||||
bool isWinding;
|
||||
|
||||
[Range(0f, .3f)] [SerializeField] float movementSmoothingTime;
|
||||
[HideInInspector] public Vector3 positionToGo;
|
||||
Vector3 currentPosition;
|
||||
Vector3 velocity;
|
||||
|
||||
Vector2 movementInput;
|
||||
bool hasMoved;
|
||||
bool moveAllowed;
|
||||
|
||||
Animator anim;
|
||||
|
||||
[SerializeField] LayerMask whatIsEnemy;
|
||||
|
||||
[Space]
|
||||
bool alreadyBeenDamaged;
|
||||
bool lowHealth;
|
||||
[SerializeField] Volume damageVolume;
|
||||
[SerializeField] Volume lowHealthVolume;
|
||||
[SerializeField] int health = 9;
|
||||
[SerializeField] GameObject[] hearts;
|
||||
|
||||
[SerializeField] GameOverCanvas gameOverCanvas;
|
||||
CanvasManager canvasManager;
|
||||
int movementsDone;
|
||||
int enemiesKilled;
|
||||
|
||||
void Awake(){
|
||||
anim = GetComponent<Animator>();
|
||||
canvasManager = FindObjectOfType<CanvasManager>();
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
positionToGo = currentPosition = transform.position;
|
||||
}
|
||||
|
||||
public void SetDifficulty(){
|
||||
moveAllowed = canvasManager.difficulty != CanvasManager.CanvasDifficulty.Hard;
|
||||
if (!moveAllowed){
|
||||
canvasManager.onHardMoveIn.AddListener(() => AllowHardMovment());
|
||||
canvasManager.onHardMoveOut.AddListener(() => DenyHardMovement());
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
movementInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
|
||||
|
||||
if (moveAllowed){
|
||||
if (canMove && !isWinding && !dead){
|
||||
if (movementInput == Vector2.zero){
|
||||
hasMoved = false;
|
||||
}else if (movementInput != Vector2.zero && !hasMoved){
|
||||
StartCoroutine(GetMovementDirection());
|
||||
hasMoved = true;
|
||||
canMove = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(Vector3.Distance(transform.position, positionToGo) > .1f){
|
||||
transform.position = Vector3.SmoothDamp(transform.position, positionToGo, ref velocity, movementSmoothingTime);
|
||||
}else if(Vector3.Distance(transform.position, positionToGo) < .1f){
|
||||
transform.position = positionToGo;
|
||||
}
|
||||
|
||||
damageVolume.weight -= Time.deltaTime;
|
||||
if (lowHealth){
|
||||
lowHealthVolume.weight = Mathf.PingPong(Time.time, 1);
|
||||
}
|
||||
|
||||
if (health <= 0 && !dead){
|
||||
AudioManager.instance.PlayOneShot("Death", true);
|
||||
canvasManager.dead = true;
|
||||
|
||||
hearts[0].SetActive(false);
|
||||
lowHealth = false;
|
||||
lowHealthVolume.weight = 0;
|
||||
|
||||
gameOverCanvas.movementsDone = movementsDone;
|
||||
gameOverCanvas.enemiesKilled = enemiesKilled;
|
||||
gameOverCanvas.gameObject.SetActive(true);
|
||||
|
||||
visualContainer.SetActive(false);
|
||||
Instantiate(deathParticles, transform.position + Vector3.up, Quaternion.identity);
|
||||
dead = true;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator GetMovementDirection(){
|
||||
movementsDone += 1;
|
||||
if(canvasManager.difficulty == CanvasManager.CanvasDifficulty.Hard){
|
||||
moveAllowed = false;
|
||||
}
|
||||
|
||||
alreadyBeenDamaged = false;
|
||||
|
||||
if(movementInput.x > 0){
|
||||
yield return new WaitForSeconds(.1f);
|
||||
if (movementInput.y > 0){
|
||||
currentPosition = positionToGo;
|
||||
positionToGo = currentPosition + new Vector3(1.25f, 0, 0);
|
||||
Collider[] cols = Physics.OverlapSphere(positionToGo, .3f, whatIsEnemy);
|
||||
if(cols.Length != 0){
|
||||
yield return new WaitForSeconds(.05f);
|
||||
ObjectPooler.instance.SpawnFromPool("EnemyDeath", new Vector3(positionToGo.x, 1, positionToGo.z), Quaternion.identity);
|
||||
PlayYesOrYeah();
|
||||
AudioManager.instance.PlayOneShot("Death", true);
|
||||
enemiesKilled += 1;
|
||||
cols[0].gameObject.SetActive(false);
|
||||
}
|
||||
}else if(movementInput.y < 0){
|
||||
currentPosition = positionToGo;
|
||||
positionToGo = currentPosition + new Vector3(0, 0, -1.25f);
|
||||
Collider[] cols = Physics.OverlapSphere(positionToGo, .3f, whatIsEnemy);
|
||||
if (cols.Length != 0){
|
||||
yield return new WaitForSeconds(.05f);
|
||||
ObjectPooler.instance.SpawnFromPool("EnemyDeath", new Vector3(positionToGo.x, 1, positionToGo.z), Quaternion.identity);
|
||||
PlayYesOrYeah();
|
||||
AudioManager.instance.PlayOneShot("Death", true);
|
||||
enemiesKilled += 1;
|
||||
cols[0].gameObject.SetActive(false);
|
||||
}
|
||||
}else{
|
||||
currentPosition = positionToGo;
|
||||
positionToGo = currentPosition + new Vector3(1.25f, 0, -1.25f);
|
||||
Collider[] cols = Physics.OverlapSphere(positionToGo, .3f, whatIsEnemy);
|
||||
if (cols.Length != 0){
|
||||
yield return new WaitForSeconds(.05f);
|
||||
ObjectPooler.instance.SpawnFromPool("EnemyDeath", new Vector3(positionToGo.x, 1, positionToGo.z), Quaternion.identity);
|
||||
PlayYesOrYeah();
|
||||
AudioManager.instance.PlayOneShot("Death", true);
|
||||
enemiesKilled += 1;
|
||||
cols[0].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
anim.SetTrigger("Moving");
|
||||
onMove.Invoke();
|
||||
yield return new WaitForSeconds(.2f);
|
||||
canMove = true;
|
||||
}else if(movementInput.x < 0){
|
||||
yield return new WaitForSeconds(.1f);
|
||||
if (movementInput.y > 0){
|
||||
currentPosition = positionToGo;
|
||||
positionToGo = currentPosition + new Vector3(0, 0, 1.25f);
|
||||
Collider[] cols = Physics.OverlapSphere(positionToGo, .3f, whatIsEnemy);
|
||||
if (cols.Length != 0){
|
||||
yield return new WaitForSeconds(.05f);
|
||||
ObjectPooler.instance.SpawnFromPool("EnemyDeath", new Vector3(positionToGo.x, 1, positionToGo.z), Quaternion.identity);
|
||||
PlayYesOrYeah();
|
||||
AudioManager.instance.PlayOneShot("Death", true);
|
||||
enemiesKilled += 1;
|
||||
cols[0].gameObject.SetActive(false);
|
||||
}
|
||||
}else if (movementInput.y < 0){
|
||||
currentPosition = positionToGo;
|
||||
positionToGo = currentPosition + new Vector3(-1.25f, 0, 0);
|
||||
Collider[] cols = Physics.OverlapSphere(positionToGo, .3f, whatIsEnemy);
|
||||
if (cols.Length != 0){
|
||||
yield return new WaitForSeconds(.05f);
|
||||
ObjectPooler.instance.SpawnFromPool("EnemyDeath", new Vector3(positionToGo.x, 1, positionToGo.z), Quaternion.identity);
|
||||
PlayYesOrYeah();
|
||||
AudioManager.instance.PlayOneShot("Death", true);
|
||||
enemiesKilled += 1;
|
||||
cols[0].gameObject.SetActive(false);
|
||||
}
|
||||
}else{
|
||||
currentPosition = positionToGo;
|
||||
positionToGo = currentPosition + new Vector3(-1.25f, 0, 1.25f);
|
||||
Collider[] cols = Physics.OverlapSphere(positionToGo, .3f, whatIsEnemy);
|
||||
if (cols.Length != 0){
|
||||
yield return new WaitForSeconds(.05f);
|
||||
ObjectPooler.instance.SpawnFromPool("EnemyDeath", new Vector3(positionToGo.x, 1, positionToGo.z), Quaternion.identity);
|
||||
PlayYesOrYeah();
|
||||
AudioManager.instance.PlayOneShot("Death", true);
|
||||
enemiesKilled += 1;
|
||||
cols[0].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
anim.SetTrigger("Moving");
|
||||
onMove.Invoke();
|
||||
yield return new WaitForSeconds(.2f);
|
||||
canMove = true;
|
||||
}else{
|
||||
if (movementInput.y > 0){
|
||||
yield return new WaitForSeconds(.1f);
|
||||
if (movementInput.x > 0){
|
||||
currentPosition = positionToGo;
|
||||
positionToGo = currentPosition + new Vector3(1.25f, 0, 0);
|
||||
Collider[] cols = Physics.OverlapSphere(positionToGo, .3f, whatIsEnemy);
|
||||
if (cols.Length != 0){
|
||||
yield return new WaitForSeconds(.05f);
|
||||
ObjectPooler.instance.SpawnFromPool("EnemyDeath", new Vector3(positionToGo.x, 1, positionToGo.z), Quaternion.identity);
|
||||
PlayYesOrYeah();
|
||||
AudioManager.instance.PlayOneShot("Death", true);
|
||||
enemiesKilled += 1;
|
||||
cols[0].gameObject.SetActive(false);
|
||||
}
|
||||
}else if (movementInput.x < 0){
|
||||
currentPosition = positionToGo;
|
||||
positionToGo = currentPosition + new Vector3(0, 0, 1.25f);
|
||||
Collider[] cols = Physics.OverlapSphere(positionToGo, .3f, whatIsEnemy);
|
||||
if (cols.Length != 0){
|
||||
yield return new WaitForSeconds(.05f);
|
||||
ObjectPooler.instance.SpawnFromPool("EnemyDeath", new Vector3(positionToGo.x, 1, positionToGo.z), Quaternion.identity);
|
||||
PlayYesOrYeah();
|
||||
AudioManager.instance.PlayOneShot("Death", true);
|
||||
enemiesKilled += 1;
|
||||
cols[0].gameObject.SetActive(false);
|
||||
}
|
||||
}else{
|
||||
currentPosition = positionToGo;
|
||||
positionToGo = currentPosition + new Vector3(1.25f, 0, 1.25f);
|
||||
Collider[] cols = Physics.OverlapSphere(positionToGo, .3f, whatIsEnemy);
|
||||
if (cols.Length != 0){
|
||||
yield return new WaitForSeconds(.05f);
|
||||
ObjectPooler.instance.SpawnFromPool("EnemyDeath", new Vector3(positionToGo.x, 1, positionToGo.z), Quaternion.identity);
|
||||
PlayYesOrYeah();
|
||||
AudioManager.instance.PlayOneShot("Death", true);
|
||||
enemiesKilled += 1;
|
||||
cols[0].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
anim.SetTrigger("Moving");
|
||||
onMove.Invoke();
|
||||
yield return new WaitForSeconds(.2f);
|
||||
canMove = true;
|
||||
}else if(movementInput.y < 0){
|
||||
yield return new WaitForSeconds(.1f);
|
||||
if (movementInput.x > 0){
|
||||
currentPosition = positionToGo;
|
||||
positionToGo = currentPosition + new Vector3(0, 0, -1.25f);
|
||||
Collider[] cols = Physics.OverlapSphere(positionToGo, .3f, whatIsEnemy);
|
||||
if (cols.Length != 0){
|
||||
yield return new WaitForSeconds(.05f);
|
||||
ObjectPooler.instance.SpawnFromPool("EnemyDeath", new Vector3(positionToGo.x, 1, positionToGo.z), Quaternion.identity);
|
||||
PlayYesOrYeah();
|
||||
AudioManager.instance.PlayOneShot("Death", true);
|
||||
enemiesKilled += 1;
|
||||
cols[0].gameObject.SetActive(false);
|
||||
}
|
||||
}else if (movementInput.x < 0){
|
||||
currentPosition = positionToGo;
|
||||
positionToGo = currentPosition + new Vector3(-1.25f, 0, 0);
|
||||
Collider[] cols = Physics.OverlapSphere(positionToGo, .3f, whatIsEnemy);
|
||||
if (cols.Length != 0){
|
||||
yield return new WaitForSeconds(.05f);
|
||||
ObjectPooler.instance.SpawnFromPool("EnemyDeath", new Vector3(positionToGo.x, 1, positionToGo.z), Quaternion.identity);
|
||||
PlayYesOrYeah();
|
||||
AudioManager.instance.PlayOneShot("Death", true);
|
||||
enemiesKilled += 1;
|
||||
cols[0].gameObject.SetActive(false);
|
||||
}
|
||||
}else{
|
||||
currentPosition = positionToGo;
|
||||
positionToGo = currentPosition + new Vector3(-1.25f, 0, -1.25f);
|
||||
Collider[] cols = Physics.OverlapSphere(positionToGo, .3f, whatIsEnemy);
|
||||
if (cols.Length != 0){
|
||||
yield return new WaitForSeconds(.05f);
|
||||
ObjectPooler.instance.SpawnFromPool("EnemyDeath", new Vector3(positionToGo.x, 1, positionToGo.z), Quaternion.identity);
|
||||
PlayYesOrYeah();
|
||||
AudioManager.instance.PlayOneShot("Death", true);
|
||||
enemiesKilled += 1;
|
||||
cols[0].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
anim.SetTrigger("Moving");
|
||||
onMove.Invoke();
|
||||
yield return new WaitForSeconds(.2f);
|
||||
canMove = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlayYesOrYeah(){
|
||||
float canRandomPlay = Random.Range(0, 100);
|
||||
if (canRandomPlay > 20 && canRandomPlay < 80){
|
||||
float whichPlay = Random.Range(0, 100);
|
||||
if (whichPlay > 50){
|
||||
AudioManager.instance.Play("Yes", true);
|
||||
}else{
|
||||
AudioManager.instance.Play("Yeah", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayMoveSoundRandomPitch(){
|
||||
AudioManager.instance.Play("PlayerStep", true);
|
||||
}
|
||||
|
||||
public void StartWind(){
|
||||
currentPosition = positionToGo;
|
||||
isWinding = true;
|
||||
alreadyBeenDamaged = false;
|
||||
}
|
||||
|
||||
public void MoveWind(Vector3 direction, int grids){
|
||||
positionToGo = transform.position + direction * grids;
|
||||
AudioManager.instance.Play("WindMove", true);
|
||||
}
|
||||
|
||||
public void EndWind(){
|
||||
isWinding = false;
|
||||
}
|
||||
|
||||
public void Damage(){
|
||||
if (!alreadyBeenDamaged){
|
||||
if (health > 0){
|
||||
hearts[health - 1].SetActive(false);
|
||||
health--;
|
||||
if (health <= 3){
|
||||
lowHealth = true;
|
||||
}
|
||||
if (health > 1){
|
||||
damageVolume.weight = 1;
|
||||
}
|
||||
|
||||
alreadyBeenDamaged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision col){
|
||||
if (col.gameObject.layer == Mathf.RoundToInt(Mathf.Log(whatIsEnemy.value, 2)) && isWinding){
|
||||
BishopController bishop = col.gameObject.GetComponent<BishopController>();
|
||||
KnightController knight = col.gameObject.GetComponent<KnightController>();
|
||||
PawnController pawn = col.gameObject.GetComponent<PawnController>();
|
||||
RookController rook = col.gameObject.GetComponent<RookController>();
|
||||
if (bishop != null){
|
||||
if (bishop.positionToGo == positionToGo){
|
||||
positionToGo = currentPosition;
|
||||
Damage();
|
||||
}
|
||||
}else if (knight != null){
|
||||
if (knight.positionToGo == positionToGo){
|
||||
positionToGo = currentPosition;
|
||||
Damage();
|
||||
}
|
||||
}else if (pawn != null){
|
||||
if (pawn.positionToGo == positionToGo){
|
||||
positionToGo = currentPosition;
|
||||
Damage();
|
||||
}
|
||||
}else if (rook != null){
|
||||
if (rook.positionToGo == positionToGo){
|
||||
positionToGo = currentPosition;
|
||||
Damage();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AllowHardMovment(){
|
||||
moveAllowed = true;
|
||||
}
|
||||
|
||||
void DenyHardMovement(){
|
||||
if (moveAllowed){
|
||||
onMove.Invoke();
|
||||
moveAllowed = false;
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerEnter(Collider col){
|
||||
if (col.CompareTag("Limits")){
|
||||
positionToGo = currentPosition;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
if (!Application.isPlaying){
|
||||
Gizmos.DrawWireSphere(transform.position + new Vector3(0, 0, 1.25f), .3f);
|
||||
Gizmos.DrawWireSphere(transform.position + new Vector3(0, 0, -1.25f), .3f);
|
||||
Gizmos.DrawWireSphere(transform.position + new Vector3(1.25f, 0, 1.25f), .3f);
|
||||
Gizmos.DrawWireSphere(transform.position + new Vector3(1.25f, 0, -1.25f), .3f);
|
||||
Gizmos.DrawWireSphere(transform.position + new Vector3(1.25f, 0, 0), .3f);
|
||||
Gizmos.DrawWireSphere(transform.position + new Vector3(-1.25f, 0, 1.25f), .3f);
|
||||
Gizmos.DrawWireSphere(transform.position + new Vector3(-1.25f, 0, -1.25f), .3f);
|
||||
Gizmos.DrawWireSphere(transform.position + new Vector3(-1.25f, 0, 0), .3f);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/PlayerController.cs.meta
Normal file
11
Assets/Scripts/PlayerController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 637e48bfbca3117438b9d485fd124591
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
45
Assets/Scripts/SceneLoader.cs
Normal file
45
Assets/Scripts/SceneLoader.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class SceneLoader : MonoBehaviour{
|
||||
|
||||
[System.Serializable] public enum DifficultySelected {Easy, Hard}
|
||||
public DifficultySelected difficultySelected;
|
||||
|
||||
Animator anim;
|
||||
|
||||
public static SceneLoader instance;
|
||||
|
||||
void Awake(){
|
||||
if(instance == null){
|
||||
instance = this;
|
||||
}else{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
anim = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
public void LoadScene(int scene, DifficultySelected difficulty){
|
||||
anim.SetTrigger("FadeOut");
|
||||
StartCoroutine(SceneChange(scene, difficulty));
|
||||
}
|
||||
|
||||
IEnumerator SceneChange(int scene, DifficultySelected difficulty){
|
||||
yield return new WaitForSeconds(1);
|
||||
difficultySelected = difficulty;
|
||||
AsyncOperation operation = SceneManager.LoadSceneAsync(scene);
|
||||
|
||||
while (!operation.isDone)
|
||||
yield return null;
|
||||
|
||||
if (operation.isDone){
|
||||
anim.SetTrigger("FadeIn");
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/SceneLoader.cs.meta
Normal file
11
Assets/Scripts/SceneLoader.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f3ea77aae3d729840b370db138bc364c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
22
Assets/Scripts/Sound.cs
Normal file
22
Assets/Scripts/Sound.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using UnityEngine.Audio;
|
||||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class Sound{
|
||||
public string name;
|
||||
|
||||
public AudioClip clip;
|
||||
|
||||
[Space]
|
||||
[Range(0, 1)] public float volume;
|
||||
[Range(0, 1)] public float volumeVariance = 0f;
|
||||
|
||||
[Space]
|
||||
[Range(.1f, 3)] public float pitch;
|
||||
[Range(0, 1)] public float pitchVariance = 0f;
|
||||
|
||||
[Space]
|
||||
public bool loop;
|
||||
|
||||
[HideInInspector] public AudioSource source;
|
||||
}
|
11
Assets/Scripts/Sound.cs.meta
Normal file
11
Assets/Scripts/Sound.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 992e18145e5950941a4691e7e21c2684
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
117
Assets/Scripts/SpawnerManager.cs
Normal file
117
Assets/Scripts/SpawnerManager.cs
Normal file
|
@ -0,0 +1,117 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SpawnerManager : MonoBehaviour{
|
||||
|
||||
[SerializeField] Vector3 offset;
|
||||
[SerializeField] Vector3 size;
|
||||
[Range(.25f, 10f)] [SerializeField] float spaceBetweenPoints = 1.25f;
|
||||
[Range(.15f, 5f)] [SerializeField] float gizmosSphereSize = .15f;
|
||||
[SerializeField] LayerMask whatPositionIsOccuped;
|
||||
|
||||
[Space]
|
||||
[SerializeField] int initialNumberToSpawn = 5;
|
||||
[SerializeField] int numberToSpawn;
|
||||
[SerializeField] string[] enemyTypes;
|
||||
List<Vector3> possiblePositions;
|
||||
|
||||
void Awake(){
|
||||
possiblePositions = new List<Vector3>();
|
||||
for (int i = 0; i < (size.z / spaceBetweenPoints); i++){
|
||||
for (int j = 0; j < (size.x / spaceBetweenPoints); j++){
|
||||
Vector3 pos = (new Vector3(offset.x - (size.x / 2), offset.y, offset.z - (size.z / 2)) + new Vector3(spaceBetweenPoints * j, 0, spaceBetweenPoints * i));
|
||||
possiblePositions.Add(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
StartCoroutine(InitialSpawn());
|
||||
}
|
||||
|
||||
IEnumerator InitialSpawn(){
|
||||
List<Vector3> pawnsPositions = new List<Vector3>();
|
||||
while (pawnsPositions.Count < initialNumberToSpawn){
|
||||
Vector3 possiblePosition = possiblePositions[Random.Range(0, possiblePositions.Count)];
|
||||
if (!pawnsPositions.Contains(possiblePosition)){
|
||||
pawnsPositions.Add(possiblePosition);
|
||||
}
|
||||
}
|
||||
foreach (Vector3 pos in pawnsPositions){
|
||||
yield return new WaitForSeconds(Random.Range(0, .02f));
|
||||
ObjectPooler.instance.SpawnFromPool(enemyTypes[0].ToString(), pos, Quaternion.identity);
|
||||
}
|
||||
|
||||
List<Vector3> rookPositions = new List<Vector3>();
|
||||
while (rookPositions.Count < initialNumberToSpawn){
|
||||
Vector3 possiblePosition = possiblePositions[Random.Range(0, possiblePositions.Count)];
|
||||
if (!rookPositions.Contains(possiblePosition)){
|
||||
rookPositions.Add(possiblePosition);
|
||||
}
|
||||
}
|
||||
foreach (Vector3 pos in rookPositions){
|
||||
yield return new WaitForSeconds(Random.Range(0, .02f));
|
||||
ObjectPooler.instance.SpawnFromPool(enemyTypes[1].ToString(), pos, Quaternion.identity);
|
||||
}
|
||||
|
||||
List<Vector3> knightPositions = new List<Vector3>();
|
||||
while (knightPositions.Count < initialNumberToSpawn){
|
||||
Vector3 possiblePosition = possiblePositions[Random.Range(0, possiblePositions.Count)];
|
||||
if (!knightPositions.Contains(possiblePosition)){
|
||||
knightPositions.Add(possiblePosition);
|
||||
}
|
||||
}
|
||||
foreach (Vector3 pos in knightPositions){
|
||||
yield return new WaitForSeconds(Random.Range(0, .02f));
|
||||
ObjectPooler.instance.SpawnFromPool(enemyTypes[2].ToString(), pos, Quaternion.identity);
|
||||
}
|
||||
|
||||
List<Vector3> bishopPositions = new List<Vector3>();
|
||||
while (bishopPositions.Count < initialNumberToSpawn){
|
||||
Vector3 possiblePosition = possiblePositions[Random.Range(0, possiblePositions.Count)];
|
||||
if (!bishopPositions.Contains(possiblePosition)){
|
||||
bishopPositions.Add(possiblePosition);
|
||||
}
|
||||
}
|
||||
foreach (Vector3 pos in bishopPositions){
|
||||
yield return new WaitForSeconds(Random.Range(0, .02f));
|
||||
ObjectPooler.instance.SpawnFromPool(enemyTypes[3].ToString(), pos, Quaternion.identity);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
|
||||
}
|
||||
|
||||
public IEnumerator Spawn(){
|
||||
List<Vector3> positions = new List<Vector3>();
|
||||
while (positions.Count < numberToSpawn){
|
||||
Vector3 possiblePosition = possiblePositions[Random.Range(0, possiblePositions.Count)];
|
||||
if(!Physics.CheckSphere(possiblePosition, .3f, whatPositionIsOccuped)){
|
||||
if (!positions.Contains(possiblePosition)){
|
||||
positions.Add(possiblePosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (Vector3 pos in positions){
|
||||
yield return new WaitForSeconds(Random.Range(0, .02f));
|
||||
ObjectPooler.instance.SpawnFromPool(enemyTypes[Mathf.RoundToInt(Random.Range(0, 300) / 100)].ToString(), pos, Quaternion.identity);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected(){
|
||||
if (!Application.isPlaying){
|
||||
Gizmos.DrawWireCube(offset, size);
|
||||
|
||||
for (int i = 0; i < (size.z / spaceBetweenPoints); i++){
|
||||
for (int j = 0; j < (size.x / spaceBetweenPoints); j++){
|
||||
Vector3 pos = (new Vector3(offset.x - (size.x / 2), offset.y, offset.z - (size.z / 2)) + new Vector3(spaceBetweenPoints * j, 0, spaceBetweenPoints * i));
|
||||
Gizmos.DrawSphere(pos, gizmosSphereSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/SpawnerManager.cs.meta
Normal file
11
Assets/Scripts/SpawnerManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bd8bbcc50cce288459c33a3749bc7bcf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/UI.meta
Normal file
8
Assets/Scripts/UI.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b0e0680307da51147ad55b767dc3fb32
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
78
Assets/Scripts/UI/CanvasManager.cs
Normal file
78
Assets/Scripts/UI/CanvasManager.cs
Normal file
|
@ -0,0 +1,78 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
[System.Serializable] public class OnHardMoveIn : UnityEvent { }
|
||||
|
||||
[System.Serializable] public class OnHardMoveOut : UnityEvent { }
|
||||
|
||||
[System.Serializable] public class OnWind : UnityEvent { }
|
||||
public class CanvasManager : MonoBehaviour{
|
||||
|
||||
[HideInInspector] public OnWind onWind;
|
||||
[HideInInspector] public OnHardMoveIn onHardMoveIn;
|
||||
[HideInInspector] public OnHardMoveOut onHardMoveOut;
|
||||
|
||||
[SerializeField] GameObject prefab;
|
||||
|
||||
[SerializeField] int turnsToWind = 5;
|
||||
int currentOne;
|
||||
[HideInInspector] public bool stopped;
|
||||
[HideInInspector] public bool dead;
|
||||
|
||||
[SerializeField] RythmBarController[] initialRythmBars;
|
||||
|
||||
[System.Serializable] public enum CanvasDifficulty {Easy, Hard}
|
||||
public CanvasDifficulty difficulty;
|
||||
|
||||
void Start(){
|
||||
if(SceneLoader.instance.difficultySelected == SceneLoader.DifficultySelected.Easy){
|
||||
difficulty = CanvasDifficulty.Easy;
|
||||
}else{
|
||||
difficulty = CanvasDifficulty.Hard;
|
||||
}
|
||||
FindObjectOfType<PlayerController>().SetDifficulty();
|
||||
foreach(RythmBarController r in initialRythmBars){
|
||||
r.SetDifficulty();
|
||||
}
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if(dead && !stopped){
|
||||
stopped = true;
|
||||
}
|
||||
}
|
||||
|
||||
public GameObject SpawnFromPool(Vector3 position, Quaternion rotation){
|
||||
GameObject objectToSpawn = Instantiate(prefab, position, rotation, transform);
|
||||
if(difficulty == CanvasDifficulty.Easy){
|
||||
objectToSpawn.GetComponent<RythmBarController>().difficulty = RythmBarController.Difficulty.Easy;
|
||||
}
|
||||
if (difficulty == CanvasDifficulty.Hard){
|
||||
objectToSpawn.GetComponent<RythmBarController>().difficulty = RythmBarController.Difficulty.Hard;
|
||||
}
|
||||
|
||||
if(currentOne == 0){
|
||||
objectToSpawn.GetComponent<RythmBarController>().IsWind();
|
||||
currentOne = turnsToWind - 1;
|
||||
}else{
|
||||
objectToSpawn.GetComponent<RythmBarController>().IsNotWind();
|
||||
currentOne--;
|
||||
}
|
||||
|
||||
return objectToSpawn;
|
||||
}
|
||||
|
||||
public void WindStart(){
|
||||
if (!dead){
|
||||
stopped = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void WindStop(){
|
||||
if (!dead){
|
||||
stopped = false;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/UI/CanvasManager.cs.meta
Normal file
11
Assets/Scripts/UI/CanvasManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 148fe82a0ed1550428d95f34f5e8b142
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
46
Assets/Scripts/UI/CutsceneTextManager.cs
Normal file
46
Assets/Scripts/UI/CutsceneTextManager.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class CutsceneTextManager : MonoBehaviour{
|
||||
|
||||
[SerializeField] Animator cutscene;
|
||||
[SerializeField] TextMeshProUGUI text;
|
||||
|
||||
[Space]
|
||||
[TextArea] [SerializeField] string[] texts;
|
||||
int currentText;
|
||||
|
||||
Animator anim;
|
||||
|
||||
void Awake(){
|
||||
anim = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (Input.anyKeyDown){
|
||||
anim.SetTrigger("Change");
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateText(){
|
||||
if((texts.Length - 1) >= currentText){
|
||||
if(currentText == 1){
|
||||
cutscene.SetTrigger("Start");
|
||||
}
|
||||
AudioManager.instance.Play("Cutscene" + (currentText + 1), false);
|
||||
text.text = texts[currentText];
|
||||
currentText++;
|
||||
}else{
|
||||
text.gameObject.SetActive(false);
|
||||
SceneLoader.instance.LoadScene(1, SceneLoader.DifficultySelected.Easy);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/UI/CutsceneTextManager.cs.meta
Normal file
11
Assets/Scripts/UI/CutsceneTextManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1ca4f242fd439d840bfd4c9f08c05c6e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
102
Assets/Scripts/UI/MainMenu.cs
Normal file
102
Assets/Scripts/UI/MainMenu.cs
Normal file
|
@ -0,0 +1,102 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using System.Linq;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MainMenu : MonoBehaviour{
|
||||
|
||||
[SerializeField] Button settingsButton;
|
||||
|
||||
[Space]
|
||||
Resolution[] resolutions;
|
||||
[SerializeField] TMP_Dropdown resolutionDropdown;
|
||||
int currentResolutionIndex;
|
||||
|
||||
[SerializeField] GameObject cutsceneText;
|
||||
Animator anim;
|
||||
bool onSettingsMenu;
|
||||
|
||||
void Start(){
|
||||
anim = GetComponent<Animator>();
|
||||
|
||||
resolutions = Screen.resolutions.Select(resolution => new Resolution { width = resolution.width, height = resolution.height }).Distinct().ToArray();
|
||||
resolutionDropdown.ClearOptions();
|
||||
|
||||
List<string> options = new List<string>();
|
||||
for (int i = 0; i < resolutions.Length; i++){
|
||||
string option = resolutions[i].width + " x " + resolutions[i].height;
|
||||
options.Add(option);
|
||||
|
||||
if(resolutions[i].width == Screen.currentResolution.width && resolutions[i].height == Screen.currentResolution.height){
|
||||
currentResolutionIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
resolutionDropdown.AddOptions(options);
|
||||
resolutionDropdown.value = currentResolutionIndex;
|
||||
resolutionDropdown.RefreshShownValue();
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if (Input.GetKeyDown(KeyCode.Escape) && onSettingsMenu){
|
||||
anim.SetTrigger("SettingsMenuExit");
|
||||
settingsButton.enabled = true;
|
||||
onSettingsMenu = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetQuality(int qualityIndex){
|
||||
QualitySettings.SetQualityLevel(qualityIndex);
|
||||
}
|
||||
|
||||
public void SetResolution(int resolutionIndex){
|
||||
Resolution resolution = resolutions[resolutionIndex];
|
||||
|
||||
Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen);
|
||||
}
|
||||
|
||||
public void SelectModeEnter(){
|
||||
if (PlayerPrefs.HasKey("AlreadyPlayed")){
|
||||
anim.SetTrigger("SelectModeEnter");
|
||||
}else{
|
||||
anim.SetTrigger("CutsceneFirstTime");
|
||||
StartCoroutine(CutscenePlay());
|
||||
PlayerPrefs.SetInt("AlreadyPlayed", 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void CutsceneEnter(){
|
||||
anim.SetTrigger("CutsceneEnter");
|
||||
StartCoroutine(CutscenePlay());
|
||||
}
|
||||
|
||||
IEnumerator CutscenePlay(){
|
||||
yield return new WaitForSeconds(1f);
|
||||
cutsceneText.SetActive(true);
|
||||
}
|
||||
|
||||
public void SettingsMenuEnter(){
|
||||
anim.SetTrigger("SettingsMenuEnter");
|
||||
settingsButton.enabled = false;
|
||||
StartCoroutine(AccessSettingsMenu());
|
||||
}
|
||||
|
||||
public void Quit(){
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
IEnumerator AccessSettingsMenu(){
|
||||
yield return new WaitForSeconds(1f);
|
||||
onSettingsMenu = true;
|
||||
}
|
||||
|
||||
public void EasyPlay(){
|
||||
SceneLoader.instance.LoadScene(1, SceneLoader.DifficultySelected.Easy);
|
||||
}
|
||||
|
||||
public void HardPlay(){
|
||||
SceneLoader.instance.LoadScene(1, SceneLoader.DifficultySelected.Hard);
|
||||
}
|
||||
}
|
11
Assets/Scripts/UI/MainMenu.cs.meta
Normal file
11
Assets/Scripts/UI/MainMenu.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 643e147e7250b4543b65fb5627dcd51b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
144
Assets/Scripts/UI/RythmBarController.cs
Normal file
144
Assets/Scripts/UI/RythmBarController.cs
Normal file
|
@ -0,0 +1,144 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class RythmBarController : MonoBehaviour{
|
||||
|
||||
[SerializeField] bool canSpawn = true;
|
||||
bool hasMoved;
|
||||
Animator anim;
|
||||
bool destroyed;
|
||||
public bool difficlutySetted = true;
|
||||
bool hardTriggered;
|
||||
|
||||
[System.Serializable] public enum Difficulty {Easy, Hard}
|
||||
public Difficulty difficulty;
|
||||
|
||||
[Header("Hard Mode Speed")]
|
||||
[SerializeField] float speed;
|
||||
|
||||
[Header("Easy Mode PositionOffset")]
|
||||
[SerializeField] Vector3 offset = new Vector2(145, 0);
|
||||
Vector3 nextLeftPos;
|
||||
Vector3 nextRightPos;
|
||||
[Range(0, .3f)] [SerializeField] float timeToMove = .1f;
|
||||
Vector2 leftVelocity;
|
||||
Vector2 rightVelocity;
|
||||
|
||||
[Space]
|
||||
[SerializeField] GameObject defaultBar;
|
||||
[SerializeField] Transform leftBar;
|
||||
[SerializeField] Transform rightBar;
|
||||
|
||||
[Header("Wind")]
|
||||
[SerializeField] GameObject windBar;
|
||||
[SerializeField] Transform leftWindBar;
|
||||
[SerializeField] Transform rightWindBar;
|
||||
bool isWind;
|
||||
|
||||
CanvasManager canvas;
|
||||
|
||||
void Awake(){
|
||||
canvas = GetComponentInParent<CanvasManager>();
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start(){
|
||||
anim = GetComponent<Animator>();
|
||||
FindObjectOfType<PlayerController>().onMove.AddListener(() => Move());
|
||||
|
||||
nextLeftPos = leftBar.localPosition;
|
||||
nextRightPos = rightBar.localPosition;
|
||||
|
||||
if (isWind){
|
||||
leftBar.gameObject.SetActive(false);
|
||||
rightBar.gameObject.SetActive(false);
|
||||
}else{
|
||||
leftWindBar.gameObject.SetActive(false);
|
||||
rightWindBar.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDifficulty(){
|
||||
if (canvas.difficulty == CanvasManager.CanvasDifficulty.Easy){
|
||||
difficulty = Difficulty.Easy;
|
||||
}else{
|
||||
difficulty = Difficulty.Hard;
|
||||
}
|
||||
|
||||
difficlutySetted = true;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (!difficlutySetted)
|
||||
return;
|
||||
|
||||
if(difficulty == Difficulty.Hard){
|
||||
if (!canvas.stopped){
|
||||
if (isWind){
|
||||
leftWindBar.transform.Translate(Vector2.right * speed * Time.deltaTime);
|
||||
rightWindBar.transform.Translate(Vector2.left * speed * Time.deltaTime);
|
||||
}else{
|
||||
leftBar.transform.Translate(Vector2.right * speed * Time.deltaTime);
|
||||
rightBar.transform.Translate(Vector2.left * speed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (difficulty == Difficulty.Easy){
|
||||
if (isWind){
|
||||
leftWindBar.localPosition = Vector2.SmoothDamp(leftWindBar.localPosition, nextLeftPos, ref leftVelocity, timeToMove);
|
||||
rightWindBar.localPosition = Vector2.SmoothDamp(rightWindBar.localPosition, nextRightPos, ref rightVelocity, timeToMove);
|
||||
}else{
|
||||
leftBar.localPosition = Vector2.SmoothDamp(leftBar.localPosition, nextLeftPos, ref leftVelocity, timeToMove);
|
||||
rightBar.localPosition = Vector2.SmoothDamp(rightBar.localPosition, nextRightPos, ref rightVelocity, timeToMove);
|
||||
}
|
||||
}
|
||||
|
||||
if(Vector2.Distance(leftBar.localPosition, rightBar.localPosition) < 175 && !hardTriggered || Vector2.Distance(leftWindBar.localPosition, rightWindBar.localPosition) < 175 && !hardTriggered){
|
||||
if(difficulty == Difficulty.Hard){
|
||||
canvas.onHardMoveIn.Invoke();
|
||||
}
|
||||
hardTriggered = true;
|
||||
}
|
||||
|
||||
if(Vector2.Distance(leftBar.localPosition, rightBar.localPosition) < 10 && !destroyed || Vector2.Distance(leftWindBar.localPosition, rightWindBar.localPosition) < 10 && !destroyed){
|
||||
if(difficulty == Difficulty.Hard){
|
||||
canvas.onHardMoveOut.Invoke();
|
||||
}
|
||||
if (isWind){
|
||||
canvas.onWind.Invoke();
|
||||
}
|
||||
destroyed = true;
|
||||
anim.SetTrigger("Fade");
|
||||
}
|
||||
}
|
||||
|
||||
public void IsWind(){
|
||||
isWind = true;
|
||||
windBar.SetActive(true);
|
||||
}
|
||||
|
||||
public void Destroy(){
|
||||
if(difficulty == Difficulty.Hard){
|
||||
canvas.SpawnFromPool(transform.position, transform.rotation);
|
||||
}
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
public void IsNotWind(){
|
||||
windBar.SetActive(false);
|
||||
}
|
||||
|
||||
void Move(){
|
||||
if (difficulty == Difficulty.Easy){
|
||||
nextLeftPos += offset;
|
||||
nextRightPos -= offset;
|
||||
if (!hasMoved && canvas != null && canSpawn){
|
||||
canvas.SpawnFromPool(transform.position, transform.rotation);
|
||||
hasMoved = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/UI/RythmBarController.cs.meta
Normal file
11
Assets/Scripts/UI/RythmBarController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5abb0ce817616204f957fbd91326d690
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
78
Assets/Scripts/WindController.cs
Normal file
78
Assets/Scripts/WindController.cs
Normal file
|
@ -0,0 +1,78 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class WindController : MonoBehaviour{
|
||||
|
||||
PlayerController player;
|
||||
CanvasManager canvas;
|
||||
SpawnerManager spawner;
|
||||
|
||||
[SerializeField] AudioSource windSource;
|
||||
[Range(0, 1)] [SerializeField] float windyVolume;
|
||||
[Range(0, 1)] [SerializeField] float defaultVolume;
|
||||
float velocity;
|
||||
bool windy;
|
||||
|
||||
[Space]
|
||||
[SerializeField] GameObject wind;
|
||||
[SerializeField] float playerMoveDelay = 2f;
|
||||
[SerializeField] float windDuration = 1f;
|
||||
|
||||
Vector3 randomDirection;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
player = FindObjectOfType<PlayerController>();
|
||||
canvas = FindObjectOfType<CanvasManager>();
|
||||
spawner = FindObjectOfType<SpawnerManager>();
|
||||
}
|
||||
|
||||
void Start(){
|
||||
canvas.onWind.AddListener(() => MovePlayer());
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if (windy){
|
||||
windSource.volume = Mathf.SmoothDamp(windSource.volume, windyVolume, ref velocity, .5f);
|
||||
}else{
|
||||
windSource.volume = Mathf.SmoothDamp(windSource.volume, defaultVolume, ref velocity, .5f);
|
||||
}
|
||||
}
|
||||
|
||||
void MovePlayer(){
|
||||
canvas.WindStart();
|
||||
randomDirection = GenerateRandomDirection();
|
||||
wind.transform.LookAt(randomDirection.normalized);
|
||||
wind.transform.rotation = Quaternion.Euler(wind.transform.eulerAngles.x, wind.transform.eulerAngles.y - 90, wind.transform.eulerAngles.z);
|
||||
wind.SetActive(true);
|
||||
player.StartWind();
|
||||
StartCoroutine(DisableWind());
|
||||
windy = true;
|
||||
}
|
||||
|
||||
Vector3 GenerateRandomDirection(){
|
||||
Vector3[] axis = new Vector3[8];
|
||||
axis[0] = Vector3.right * 1.25f;
|
||||
axis[1] = Vector3.left * 1.25f;
|
||||
axis[2] = Vector3.forward * 1.25f;
|
||||
axis[3] = Vector3.back * 1.25f;
|
||||
axis[4] = new Vector3(1.25f, 0, 1.25f);
|
||||
axis[5] = new Vector3(-1.25f, 0, 1.25f);
|
||||
axis[6] = new Vector3(1.25f, 0, -1.25f);
|
||||
axis[7] = new Vector3(-1.25f, 0, -1.25f);
|
||||
|
||||
return axis[Random.Range(0, 7)];
|
||||
}
|
||||
|
||||
IEnumerator DisableWind(){
|
||||
yield return new WaitForSeconds(playerMoveDelay);
|
||||
player.MoveWind(randomDirection, Mathf.RoundToInt(Random.Range(50, 149) / 50));
|
||||
spawner.StartCoroutine(spawner.Spawn());
|
||||
yield return new WaitForSeconds(windDuration);
|
||||
windy = false;
|
||||
wind.SetActive(false);
|
||||
player.EndWind();
|
||||
canvas.WindStop();
|
||||
}
|
||||
}
|
11
Assets/Scripts/WindController.cs.meta
Normal file
11
Assets/Scripts/WindController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a3174ee33547e9c488868181cfa2d213
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue