init
This commit is contained in:
commit
102013b228
1443 changed files with 1065651 additions and 0 deletions
8
Assets/Scripts/BalloonFight.meta
Normal file
8
Assets/Scripts/BalloonFight.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 70a8ab179a14bb540922d0000a04aaf4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
297
Assets/Scripts/BalloonFight/BallonPlayerController.cs
Normal file
297
Assets/Scripts/BalloonFight/BallonPlayerController.cs
Normal file
|
@ -0,0 +1,297 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BallonPlayerController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] ScenesTransitionController scenesTransition;
|
||||
[SerializeField] GameTutorialControler tutorial;
|
||||
[SerializeField] LayerMask whatIsGround = -1;
|
||||
Camera cam;
|
||||
|
||||
[SerializeField] float speed = 6f;
|
||||
[SerializeField] float splashSpeed = 4f;
|
||||
[SerializeField] float gravityScale = 9.8f;
|
||||
[SerializeField] Transform feetPos = default;
|
||||
[SerializeField] float feetRadius = .3f;
|
||||
float currentSpeed;
|
||||
Vector3 velocity;
|
||||
bool isGrounded;
|
||||
|
||||
bool moving;
|
||||
CharacterController controller;
|
||||
|
||||
[SerializeField] Animator anim = default;
|
||||
[SerializeField] float turnSmoothTime = .1f;
|
||||
float turnSmoothVelocity;
|
||||
bool canShootAgain;
|
||||
bool needABalloon;
|
||||
bool charging;
|
||||
bool shooting;
|
||||
bool isDead;
|
||||
|
||||
float yVelocity;
|
||||
float velocityChangeVelocity;
|
||||
|
||||
[SerializeField] Transform shootPos = default;
|
||||
|
||||
[SerializeField, Range(0f, 1f)] float timeToShoot = .5f;
|
||||
float currentTime;
|
||||
|
||||
[Space]
|
||||
[SerializeField, Range(0, 30)] float onSplashDecreaseSpeed = .5f;
|
||||
[SerializeField] float maxHp = 100;
|
||||
public float hp;
|
||||
[SerializeField] GameObject balloon = default;
|
||||
|
||||
[SerializeField] Color splashColor = Color.red;
|
||||
[System.Serializable] public class BodyMaterials{
|
||||
public Material[] bodyMats;
|
||||
}
|
||||
|
||||
[SerializeField] BodyMaterials[] characterMats;
|
||||
CharacterIdController character;
|
||||
|
||||
[Space]
|
||||
[SerializeField] Canvas canvas = default;
|
||||
[SerializeField] UnityEngine.UI.Image chargingBar = default;
|
||||
|
||||
bool scoreDistributed;
|
||||
|
||||
private bool boolSoundActived = false;
|
||||
|
||||
[SerializeField, Range(0, 1f)] float stepsInterval = .35f;
|
||||
float currentStepTime;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
character = GetComponent<CharacterIdController>();
|
||||
hp = maxHp;
|
||||
currentSpeed = speed;
|
||||
moving = true;
|
||||
cam = Camera.main;
|
||||
controller = GetComponent<CharacterController>();
|
||||
|
||||
anim = character.SetPlayerCustom();
|
||||
|
||||
foreach (Material bodyMat in characterMats[character.characterId].bodyMats)
|
||||
bodyMat.SetColor("Color_9AC6EC04", splashColor);
|
||||
|
||||
foreach(BodyMaterials body in characterMats)
|
||||
foreach (Material bodyMat in body.bodyMats)
|
||||
bodyMat.SetFloat("Vector1_104BE5AC", Mathf.Lerp(-1, 1.5f, 1 - hp / maxHp));
|
||||
|
||||
StartCoroutine(AudioManager.instance.FadeIn("transicion", 1));
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
if (tutorial.gameStarted && !isDead)
|
||||
{
|
||||
if (!boolSoundActived)
|
||||
{
|
||||
boolSoundActived = true;
|
||||
StartCoroutine(AudioManager.instance.FadeOut("transicion", 1));
|
||||
StartCoroutine(AudioManager.instance.FadeIn("05_globos", 1));
|
||||
}
|
||||
|
||||
balloon.SetActive(!needABalloon);
|
||||
|
||||
#region Shoot
|
||||
if (Input.GetMouseButtonUp(0) && currentTime >= timeToShoot && !needABalloon && !charging && canShootAgain)
|
||||
{
|
||||
Shoot();
|
||||
canShootAgain = false;
|
||||
}
|
||||
|
||||
if (Input.GetMouseButton(0) && canShootAgain && !needABalloon)
|
||||
{
|
||||
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
|
||||
RaycastHit hit;
|
||||
|
||||
if (Physics.Raycast(ray, out hit, whatIsGround))
|
||||
{
|
||||
Vector3 pos = hit.point - transform.position;
|
||||
float rotY = Mathf.Atan2(-pos.z, pos.x) * Mathf.Rad2Deg;
|
||||
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, rotY + 90, ref turnSmoothVelocity, turnSmoothTime);
|
||||
transform.rotation = Quaternion.Euler(0f, angle, 0f);
|
||||
}
|
||||
|
||||
moving = false;
|
||||
currentTime = Mathf.Clamp(currentTime + Time.deltaTime, 0, timeToShoot);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!charging)
|
||||
{
|
||||
currentTime = Mathf.Clamp(currentTime - Time.deltaTime * 2, 0, timeToShoot);
|
||||
if (currentTime <= 0)
|
||||
{
|
||||
canShootAgain = true;
|
||||
}
|
||||
}
|
||||
moving = true;
|
||||
}
|
||||
|
||||
chargingBar.transform.localScale = new Vector3(Mathf.Clamp(currentTime / timeToShoot, 0, 1), 1);
|
||||
#endregion
|
||||
|
||||
isGrounded = Physics.CheckSphere(feetPos.position, feetRadius, whatIsGround);
|
||||
|
||||
if (moving && !shooting)
|
||||
{
|
||||
Vector3 direction = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
|
||||
|
||||
if (direction.magnitude > .1f)
|
||||
{
|
||||
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
|
||||
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
|
||||
transform.rotation = Quaternion.Euler(0f, angle, 0f);
|
||||
|
||||
controller.Move(direction * currentSpeed * Time.deltaTime);
|
||||
yVelocity = 1;
|
||||
|
||||
currentStepTime += Time.deltaTime;
|
||||
if (currentStepTime >= stepsInterval){
|
||||
AudioManager.instance.PlayOneShot("SFX_paso" + Random.Range(1, 6), true);
|
||||
currentStepTime = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
yVelocity = 0;
|
||||
}
|
||||
|
||||
if(hp <= 0 && !isDead){
|
||||
anim.SetTrigger("Die");
|
||||
isDead = true;
|
||||
ReturnToMenu(GameObject.Find("Enemy").GetComponent<CharacterIdController>().characterId, GetComponent<CharacterIdController>().characterId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
yVelocity = 0;
|
||||
}
|
||||
|
||||
anim.SetFloat("VelocityY", Mathf.SmoothDamp(anim.GetFloat("VelocityY"), yVelocity, ref velocityChangeVelocity, .1f));
|
||||
|
||||
if (isGrounded && velocity.y < 0)
|
||||
{
|
||||
velocity.y = -2f;
|
||||
}
|
||||
|
||||
velocity.y -= gravityScale * Time.deltaTime;
|
||||
controller.Move(velocity * Time.deltaTime);
|
||||
|
||||
foreach (Material bodyMat in characterMats[character.characterId].bodyMats)
|
||||
bodyMat.SetFloat("Vector1_104BE5AC", Mathf.Lerp(-1, 1.5f, 1 - hp / maxHp));
|
||||
}
|
||||
}
|
||||
|
||||
void LateUpdate(){
|
||||
canvas.transform.rotation = Quaternion.Euler(45, 0, 0);
|
||||
}
|
||||
|
||||
void Shoot(){
|
||||
anim.SetTrigger("Throw");
|
||||
needABalloon = true;
|
||||
shooting = true;
|
||||
StartCoroutine(ShootBalloon());
|
||||
}
|
||||
|
||||
IEnumerator ShootBalloon(){
|
||||
yield return new WaitForSeconds(.5f);
|
||||
ObjectPooler.instance.SpawnFromPool("OrangeBalloon", shootPos.position, shootPos.rotation);
|
||||
shooting = false;
|
||||
}
|
||||
|
||||
void OnTriggerStay(Collider col){
|
||||
if (col.CompareTag("BlueSplash")){
|
||||
currentSpeed = splashSpeed;
|
||||
hp -= onSplashDecreaseSpeed * Time.deltaTime;
|
||||
}
|
||||
|
||||
if (col.CompareTag("BalloonTrigger")){
|
||||
if (Input.GetMouseButtonUp(0) && currentTime >= timeToShoot && needABalloon){
|
||||
anim.SetTrigger("Lift");
|
||||
currentTime = 0;
|
||||
needABalloon = false;
|
||||
canShootAgain = false;
|
||||
charging = false;
|
||||
}
|
||||
|
||||
if (Input.GetMouseButton(0) && canShootAgain && needABalloon){
|
||||
charging = true;
|
||||
moving = false;
|
||||
currentTime = Mathf.Clamp(currentTime + Time.deltaTime, 0, timeToShoot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit(Collider col){
|
||||
if (col.CompareTag("BlueSplash")){
|
||||
currentSpeed = speed;
|
||||
}
|
||||
|
||||
if (col.CompareTag("BalloonTrigger")){
|
||||
if(currentTime >= timeToShoot && needABalloon){
|
||||
needABalloon = false;
|
||||
canShootAgain = false;
|
||||
charging = false;
|
||||
}else if (needABalloon){
|
||||
currentTime = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ReturnToMenu(int winner, int looser)
|
||||
{
|
||||
StartCoroutine(AudioManager.instance.FadeOut("05_globos", 1));
|
||||
if (!scoreDistributed)
|
||||
{
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Baloons,
|
||||
winner,
|
||||
null));
|
||||
|
||||
int newWinner1 = winner;
|
||||
int i = 0;
|
||||
while (i < 100)
|
||||
{
|
||||
newWinner1 = Random.Range(0, 6);
|
||||
i++;
|
||||
if (newWinner1 != winner && newWinner1 != looser)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Baloons,
|
||||
newWinner1,
|
||||
null));
|
||||
|
||||
int newWinner2;
|
||||
newWinner2 = winner;
|
||||
i = 0;
|
||||
while (i < 100)
|
||||
{
|
||||
newWinner2 = Random.Range(0, 6);
|
||||
i++;
|
||||
if (newWinner2 != winner && newWinner2 != looser && newWinner2 != newWinner1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Baloons,
|
||||
newWinner2,
|
||||
scenesTransition,
|
||||
1.5f));
|
||||
scoreDistributed = true;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/BalloonFight/BallonPlayerController.cs.meta
Normal file
11
Assets/Scripts/BalloonFight/BallonPlayerController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4a8a8944b54f7b441bad49c89e47a05c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
47
Assets/Scripts/BalloonFight/BalloonController.cs
Normal file
47
Assets/Scripts/BalloonFight/BalloonController.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BalloonController : MonoBehaviour, IPooledObject{
|
||||
|
||||
[SerializeField] float shootForce = 10f;
|
||||
[SerializeField] string nameOfTheSplash = "OrangeSplash";
|
||||
[SerializeField] string enemyTag = "Enemy";
|
||||
Rigidbody rb;
|
||||
[SerializeField, Range(1, 3)] int jumpsToExplode = 3;
|
||||
int currentJump;
|
||||
|
||||
void Awake(){
|
||||
rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
public void OnObjectSpawn(){
|
||||
currentJump = 1;
|
||||
rb.velocity = Vector3.zero;
|
||||
rb.angularVelocity = Vector3.zero;
|
||||
rb.AddForce(transform.forward * shootForce, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision col){
|
||||
if(col.gameObject.CompareTag("Ground")){
|
||||
if(currentJump < jumpsToExplode){
|
||||
GameObject splash = ObjectPooler.instance.SpawnFromPool(nameOfTheSplash, new Vector3(transform.position.x, .15f, transform.position.z), Quaternion.Euler(0, Random.Range(0f, 360f), 0));
|
||||
splash.transform.localScale = new Vector3(1, .15f, 1);
|
||||
AudioManager.instance.PlayOneShot("SFX_globoFalla", true);
|
||||
currentJump++;
|
||||
}else{
|
||||
GameObject splash = ObjectPooler.instance.SpawnFromPool(nameOfTheSplash, new Vector3(transform.position.x, .15f, transform.position.z), Quaternion.Euler(0, Random.Range(0f, 360f), 0));
|
||||
splash.transform.localScale = new Vector3(2, .15f, 2);
|
||||
AudioManager.instance.PlayOneShot("SFX_globoImpacta", true);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (col.gameObject.CompareTag(enemyTag)){
|
||||
GameObject splash = ObjectPooler.instance.SpawnFromPool(nameOfTheSplash, new Vector3(transform.position.x, .15f, transform.position.z), Quaternion.Euler(0, Random.Range(0f, 360f), 0));
|
||||
splash.transform.localScale = new Vector3(2, .15f, 2);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/BalloonFight/BalloonController.cs.meta
Normal file
11
Assets/Scripts/BalloonFight/BalloonController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 58409a7c5fda95d4982bfb9333bb7f26
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
238
Assets/Scripts/BalloonFight/BalloonEnemyController.cs
Normal file
238
Assets/Scripts/BalloonFight/BalloonEnemyController.cs
Normal file
|
@ -0,0 +1,238 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class BalloonEnemyController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] ScenesTransitionController scenesTransition;
|
||||
[SerializeField] GameTutorialControler tutorial;
|
||||
|
||||
[SerializeField] Animator anim = default;
|
||||
[SerializeField] Transform player = default;
|
||||
[SerializeField] Transform basketPos = default;
|
||||
NavMeshAgent agent;
|
||||
|
||||
[Space]
|
||||
[SerializeField] Transform shootPos = default;
|
||||
[SerializeField] Vector2 xPos = new Vector2(1, 10);
|
||||
float maxXPos;
|
||||
[SerializeField] float speed = 6f;
|
||||
[SerializeField] float splashSpeed = 3f;
|
||||
[SerializeField] Vector2 timeToShoot = new Vector2(.25f, 2f);
|
||||
float currentSpeed;
|
||||
float rotationVelocity;
|
||||
[SerializeField, Range(0, .3f)] float turnSmoothTime = .1f;
|
||||
float timeSelected;
|
||||
float currentTime;
|
||||
bool canMove;
|
||||
bool needBalloons;
|
||||
|
||||
[SerializeField, Range(0, 10)] float onSplashDecreaseSpeed = .5f;
|
||||
[SerializeField] float maxHp = 100;
|
||||
[SerializeField] float hp;
|
||||
|
||||
[SerializeField] Color splashColor = Color.red;
|
||||
[System.Serializable]
|
||||
public class BodyMaterials{
|
||||
public Material[] bodyMats;
|
||||
}
|
||||
|
||||
[SerializeField] BodyMaterials[] characterMats;
|
||||
CharacterIdController character;
|
||||
|
||||
[Space]
|
||||
[SerializeField] Canvas canvas = default;
|
||||
[SerializeField] UnityEngine.UI.Image chargingBar = default;
|
||||
[SerializeField] GameObject balloon = default;
|
||||
|
||||
bool isDead;
|
||||
bool scoreDistributed;
|
||||
|
||||
[SerializeField, Range(0, 1f)] float stepsInterval = .35f;
|
||||
float currentStepTime;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
character = GetComponent<CharacterIdController>();
|
||||
agent = GetComponent<NavMeshAgent>();
|
||||
currentSpeed = speed;
|
||||
canMove = true;
|
||||
maxXPos = Random.Range(xPos.x, xPos.y);
|
||||
anim = character.SetRandomNpcCustom();
|
||||
|
||||
hp = maxHp;
|
||||
|
||||
foreach (Material bodyMat in characterMats[character.characterId].bodyMats)
|
||||
bodyMat.SetColor("Color_9AC6EC04", splashColor);
|
||||
|
||||
foreach (BodyMaterials body in characterMats)
|
||||
foreach (Material bodyMat in body.bodyMats)
|
||||
bodyMat.SetFloat("Vector1_104BE5AC", Mathf.Lerp(-1, 1.5f, 1 - hp / maxHp));
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (tutorial.gameStarted) {
|
||||
balloon.SetActive(!needBalloons);
|
||||
|
||||
if(canMove && !needBalloons){
|
||||
agent.SetDestination(new Vector3(maxXPos, 0, player.position.z));
|
||||
anim.SetFloat("VelocityY", 1);
|
||||
|
||||
currentStepTime += Time.deltaTime;
|
||||
if (currentStepTime >= stepsInterval){
|
||||
AudioManager.instance.PlayOneShot("SFX_paso" + Random.Range(1, 6), true);
|
||||
currentStepTime = 0;
|
||||
}
|
||||
}
|
||||
else if (needBalloons){
|
||||
anim.SetFloat("VelocityY", 1);
|
||||
agent.SetDestination(new Vector3(10, 0, basketPos.position.z));
|
||||
|
||||
currentStepTime += Time.deltaTime;
|
||||
if (currentStepTime >= stepsInterval){
|
||||
AudioManager.instance.PlayOneShot("SFX_paso" + Random.Range(1, 6), true);
|
||||
currentStepTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ((new Vector3(maxXPos, transform.position.y, player.position.z) - transform.position).sqrMagnitude < agent.stoppingDistance * agent.stoppingDistance && !needBalloons || canMove == false){
|
||||
anim.SetFloat("VelocityY", 0);
|
||||
Vector3 direction = new Vector3(player.position.x - transform.position.x, transform.position.y, player.position.z - transform.position.z).normalized;
|
||||
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
|
||||
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref rotationVelocity, turnSmoothTime);
|
||||
|
||||
transform.rotation = Quaternion.Euler(0, angle, 0);
|
||||
|
||||
if(Mathf.Abs(transform.eulerAngles.y - angle) < .5f){
|
||||
if(canMove == false){
|
||||
currentTime = Mathf.Clamp(currentTime + Time.deltaTime, 0, timeSelected);
|
||||
chargingBar.transform.localScale = new Vector3(Mathf.Clamp(currentTime / timeSelected, 0, 1), 1);
|
||||
if (currentTime >= timeSelected && !shooting){
|
||||
StartCoroutine(ShootDelay());
|
||||
}
|
||||
}else{
|
||||
timeSelected = Random.Range(timeToShoot.x, timeToShoot.y);
|
||||
currentTime = 0;
|
||||
chargingBar.transform.localScale = new Vector3(0, 1, 1);
|
||||
canMove = false;
|
||||
maxXPos = Random.Range(xPos.x, xPos.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((new Vector3(10, transform.position.y, basketPos.position.z) - transform.position).sqrMagnitude < agent.stoppingDistance * agent.stoppingDistance && needBalloons && !gettingABalloon){
|
||||
StartCoroutine(GetABalloon());
|
||||
anim.SetFloat("VelocityY", 0);
|
||||
}
|
||||
|
||||
agent.speed = currentSpeed;
|
||||
|
||||
foreach (Material bodyMat in characterMats[character.characterId].bodyMats)
|
||||
bodyMat.SetFloat("Vector1_104BE5AC", Mathf.Lerp(-1, 1.5f, 1 - hp / maxHp));
|
||||
|
||||
if (hp <= 0 && !isDead)
|
||||
{
|
||||
anim.SetTrigger("Die");
|
||||
isDead = true;
|
||||
ReturnToMenu(GameObject.Find("Player").GetComponent<CharacterIdController>().characterId, GetComponent<CharacterIdController>().characterId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LateUpdate(){
|
||||
canvas.transform.rotation = Quaternion.Euler(45, 0, 0);
|
||||
}
|
||||
|
||||
bool gettingABalloon;
|
||||
IEnumerator GetABalloon(){
|
||||
gettingABalloon = true;
|
||||
anim.SetTrigger("Lift");
|
||||
yield return new WaitForSeconds(.5f);
|
||||
needBalloons = false;
|
||||
gettingABalloon = false;
|
||||
StopCoroutine(GetABalloon());
|
||||
}
|
||||
|
||||
bool shooting;
|
||||
|
||||
IEnumerator ShootDelay(){
|
||||
anim.SetTrigger("Throw");
|
||||
shooting = true;
|
||||
yield return new WaitForSeconds(.7f);
|
||||
chargingBar.transform.localScale = new Vector3(0, 1, 1);
|
||||
Shoot();
|
||||
canMove = true;
|
||||
shooting = false;
|
||||
StopAllCoroutines();
|
||||
}
|
||||
|
||||
void Shoot(){
|
||||
needBalloons = true;
|
||||
ObjectPooler.instance.SpawnFromPool("BlueBalloon", shootPos.position, shootPos.rotation);
|
||||
}
|
||||
|
||||
void OnTriggerStay(Collider col){
|
||||
if (col.CompareTag("OrangeSplash")){
|
||||
hp -= onSplashDecreaseSpeed * Time.deltaTime;
|
||||
currentSpeed = splashSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit(Collider col){
|
||||
if (col.CompareTag("OrangeSplash")){
|
||||
currentSpeed = speed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ReturnToMenu(int winner, int looser)
|
||||
{
|
||||
StartCoroutine(AudioManager.instance.FadeOut("05_globos", 1));
|
||||
if (!scoreDistributed)
|
||||
{
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Baloons,
|
||||
winner,
|
||||
null));
|
||||
|
||||
int newWinner1 = winner;
|
||||
int i = 0;
|
||||
while (i < 100)
|
||||
{
|
||||
newWinner1 = Random.Range(0, 6);
|
||||
i++;
|
||||
if (newWinner1 != winner && newWinner1 != looser)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Baloons,
|
||||
newWinner1,
|
||||
null));
|
||||
|
||||
int newWinner2;
|
||||
newWinner2 = winner;
|
||||
i = 0;
|
||||
while (i < 100)
|
||||
{
|
||||
newWinner2 = Random.Range(0, 6);
|
||||
i++;
|
||||
if (newWinner2 != winner && newWinner2 != looser && newWinner2 != newWinner1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Baloons,
|
||||
newWinner2,
|
||||
scenesTransition,
|
||||
1.5f));
|
||||
scoreDistributed = true;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/BalloonFight/BalloonEnemyController.cs.meta
Normal file
11
Assets/Scripts/BalloonFight/BalloonEnemyController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d1c432234f0b2274ba7e881f8c6845b4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
33
Assets/Scripts/BalloonFight/BalloonSplash.cs
Normal file
33
Assets/Scripts/BalloonFight/BalloonSplash.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BalloonSplash : MonoBehaviour, IPooledObject{
|
||||
|
||||
[SerializeField] float timeToDisappear = 10f;
|
||||
[SerializeField] float disappearDuration = 1f;
|
||||
float currentTime;
|
||||
|
||||
Animator anim;
|
||||
|
||||
void Awake(){
|
||||
anim = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
public void OnObjectSpawn(){
|
||||
currentTime = 0;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
currentTime += Time.deltaTime;
|
||||
if (currentTime >= timeToDisappear - disappearDuration){
|
||||
anim.SetTrigger("Destroy");
|
||||
}
|
||||
}
|
||||
|
||||
public void Disable(){
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
11
Assets/Scripts/BalloonFight/BalloonSplash.cs.meta
Normal file
11
Assets/Scripts/BalloonFight/BalloonSplash.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e3de89a3fb0d3f3498c5c83a04d15828
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
143
Assets/Scripts/BetweenScenePass.cs
Normal file
143
Assets/Scripts/BetweenScenePass.cs
Normal file
|
@ -0,0 +1,143 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BetweenScenePass : MonoBehaviour
|
||||
{
|
||||
|
||||
public static BetweenScenePass instance;
|
||||
|
||||
[Header("GamesPlayed")]
|
||||
[SerializeField] Dictionary<Games, bool> gamesPlayed;
|
||||
[SerializeField] Dictionary<Games, string> gamesScenes;
|
||||
|
||||
public enum Games { Swords, Sacks, Chairs, Jousting, Baloons };
|
||||
[SerializeField] bool gameRestarted = true;
|
||||
|
||||
[Header("Skins")]
|
||||
[SerializeField] int playerCharacterId;
|
||||
[SerializeField] List<int> npcCharacterId;
|
||||
|
||||
[Space(10)]
|
||||
[SerializeField] Dictionary<Games, Dictionary<int, int>> characterScore;
|
||||
|
||||
|
||||
public bool GameRestarted { get => gameRestarted; set => gameRestarted = value; }
|
||||
public int PlayerCharacterId { get => playerCharacterId; set => playerCharacterId = value; }
|
||||
public Dictionary<Games, bool> GamesPlayed { get => gamesPlayed; set => gamesPlayed = value; }
|
||||
public Dictionary<Games, string> GamesScenes { get => gamesScenes; set => gamesScenes = value; }
|
||||
public Dictionary<Games, Dictionary<int, int>> CharacterScore { get => characterScore; set => characterScore = value; }
|
||||
public List<int> NpcCharacterId { get => npcCharacterId; set => npcCharacterId = value; }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = this;
|
||||
GameRestarted = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
if (GameRestarted)
|
||||
{
|
||||
Debug.Log("Restart Game");
|
||||
RestartData();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void RestartData()
|
||||
{
|
||||
GamesPlayed = new Dictionary<Games, bool>();
|
||||
GamesScenes = new Dictionary<Games, string>();
|
||||
|
||||
GamesPlayed[Games.Swords] = false;
|
||||
GamesPlayed[Games.Sacks] = false;
|
||||
GamesPlayed[Games.Chairs] = false;
|
||||
GamesPlayed[Games.Jousting] = false;
|
||||
GamesPlayed[Games.Baloons] = false;
|
||||
|
||||
GamesScenes[Games.Swords] = "Scenes/Espadas";
|
||||
GamesScenes[Games.Sacks] = "Scenes/CarreraSacos";
|
||||
GamesScenes[Games.Chairs] = "Scenes/Sillas";
|
||||
GamesScenes[Games.Jousting] = "Scenes/Justa";
|
||||
GamesScenes[Games.Baloons] = "Scenes/Globos";
|
||||
|
||||
PlayerCharacterId = -1;
|
||||
NpcCharacterId = new List<int>();
|
||||
|
||||
CharacterScore = new Dictionary<Games, Dictionary<int, int>>();
|
||||
|
||||
CharacterScore[Games.Swords] = new Dictionary<int, int>();
|
||||
for(int i = 0; i < 6; i++)
|
||||
{
|
||||
CharacterScore[Games.Swords][i] = 0;
|
||||
}
|
||||
|
||||
CharacterScore[Games.Sacks] = new Dictionary<int, int>();
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
CharacterScore[Games.Sacks][i] = 0;
|
||||
}
|
||||
CharacterScore[Games.Chairs] = new Dictionary<int, int>();
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
CharacterScore[Games.Chairs][i] = 0;
|
||||
}
|
||||
CharacterScore[Games.Jousting] = new Dictionary<int, int>();
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
CharacterScore[Games.Jousting][i] = 0;
|
||||
}
|
||||
CharacterScore[Games.Baloons] = new Dictionary<int, int>();
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
CharacterScore[Games.Baloons][i] = 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public IEnumerator DistributeScore(Games playerGame, int winner, ScenesTransitionController scenesTransition)
|
||||
{
|
||||
|
||||
Debug.Log("SE ASIGNA 1 PUNTO AL PERSONAJE " + winner);
|
||||
|
||||
yield return new WaitForSeconds(1f);
|
||||
CharacterScore[playerGame][winner] += 1;
|
||||
GamesPlayed[playerGame] = true;
|
||||
if (scenesTransition != null)
|
||||
{
|
||||
GameRestarted = false;
|
||||
|
||||
if (GamesPlayed[Games.Swords] &&
|
||||
GamesPlayed[Games.Sacks] &&
|
||||
GamesPlayed[Games.Chairs] &&
|
||||
GamesPlayed[Games.Jousting] &&
|
||||
GamesPlayed[Games.Baloons])
|
||||
{
|
||||
AudioManager.instance.StopAll();
|
||||
scenesTransition.CloseScene("Scenes/EndGame");
|
||||
}
|
||||
else
|
||||
{
|
||||
AudioManager.instance.StopAll();
|
||||
scenesTransition.CloseScene("Scenes/Menu");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator DistributeScore(Games playerGame, int winner, ScenesTransitionController scenesTransition, float delay)
|
||||
{
|
||||
|
||||
yield return new WaitForSeconds(delay);
|
||||
StartCoroutine(DistributeScore(playerGame, winner, scenesTransition));
|
||||
}
|
||||
}
|
11
Assets/Scripts/BetweenScenePass.cs.meta
Normal file
11
Assets/Scripts/BetweenScenePass.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 948409d016db5284491c4f4866db4eb5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/ChairsGame.meta
Normal file
8
Assets/Scripts/ChairsGame.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 91af3fd21586a8747abd2b7d07f5f9d7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
46
Assets/Scripts/ChairsGame/ChairsChairController.cs
Normal file
46
Assets/Scripts/ChairsGame/ChairsChairController.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ChairsChairController : MonoBehaviour
|
||||
{
|
||||
|
||||
public bool occupied;
|
||||
public bool assigned;
|
||||
|
||||
[SerializeField] ChairsGameController gameController;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void AssignSeat()
|
||||
{
|
||||
this.occupied = true;
|
||||
gameController.OccupyChair(this);
|
||||
}
|
||||
|
||||
/*
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Enemy"))
|
||||
{
|
||||
if (occupied)
|
||||
{
|
||||
other.GetComponent<ChairsEnemyController>().ChooseNewChair();
|
||||
}
|
||||
else
|
||||
{
|
||||
occupied = true;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
11
Assets/Scripts/ChairsGame/ChairsChairController.cs.meta
Normal file
11
Assets/Scripts/ChairsGame/ChairsChairController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2bd7054af15d8af4dbef7df819757615
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
310
Assets/Scripts/ChairsGame/ChairsEnemyController.cs
Normal file
310
Assets/Scripts/ChairsGame/ChairsEnemyController.cs
Normal file
|
@ -0,0 +1,310 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class ChairsEnemyController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] public Animator anim;
|
||||
|
||||
[SerializeField] const float normalSpeed = 6f;
|
||||
[SerializeField] const float stunnedSpeed = 3f;
|
||||
//float speed = 6;
|
||||
|
||||
[SerializeField] NavMeshAgent agent;
|
||||
[SerializeField] ChairsGameController gameController;
|
||||
|
||||
[SerializeField] ChairsChairController targetChair;
|
||||
|
||||
//[SerializeField] float gravity = -9.8f;
|
||||
|
||||
[SerializeField] float findNewChairDelay;
|
||||
|
||||
[SerializeField] float stunCoolDown;
|
||||
float actualStunCoolDown;
|
||||
[SerializeField] float stunDuration;
|
||||
|
||||
public bool sat = false;
|
||||
|
||||
/*[HideInInspector]*/ public Vector3 startPosition;
|
||||
|
||||
//bool canMove = true;
|
||||
public bool stunned = false;
|
||||
|
||||
public bool paused = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
startPosition = this.transform.position;
|
||||
|
||||
}
|
||||
|
||||
public void InitGame()
|
||||
{
|
||||
SetInitialTargetChair();
|
||||
agent.SetDestination(targetChair.gameObject.transform.position);
|
||||
SetNewTargetChair();
|
||||
}
|
||||
|
||||
public void SetInitialTargetChair()
|
||||
{
|
||||
float maxDistance = float.PositiveInfinity;
|
||||
int selectedIndex = 0;
|
||||
for (int i = 0; i < gameController.freeChairs.Count; i++)
|
||||
{
|
||||
if (!gameController.freeChairs[i].occupied)
|
||||
{
|
||||
float distance = Vector3.Distance(this.transform.position, gameController.freeChairs[i].gameObject.transform.position);
|
||||
if (distance < maxDistance)
|
||||
{
|
||||
selectedIndex = i;
|
||||
maxDistance = distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
targetChair = gameController.freeChairs[selectedIndex];
|
||||
}
|
||||
|
||||
public void SetNewTargetChair()
|
||||
{
|
||||
StartCoroutine(SetNewTargetChairCoroutine());
|
||||
}
|
||||
|
||||
public IEnumerator SetNewTargetChairCoroutine()
|
||||
{
|
||||
while (!sat && gameController.freeChairs.Count> 0)
|
||||
{
|
||||
if (!this.stunned)
|
||||
{
|
||||
float maxDistance = float.PositiveInfinity;
|
||||
int selectedIndex = 0;
|
||||
for (int i = 0; i < gameController.freeChairs.Count; i++)
|
||||
{
|
||||
if (!gameController.freeChairs[i].occupied)
|
||||
{
|
||||
NavMeshPath path = new NavMeshPath();
|
||||
agent.CalculatePath(gameController.freeChairs[i].transform.position, path);
|
||||
float distance = GetPathLength(path);/*= Vector3.Distance(this.transform.position, gameController.freeChairs[i].gameObject.transform.position)*/
|
||||
|
||||
if (distance < maxDistance)
|
||||
{
|
||||
selectedIndex = i;
|
||||
maxDistance = distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (targetChair == null)
|
||||
{
|
||||
ChairsChairController chair = gameController.freeChairs[selectedIndex];
|
||||
targetChair = chair;
|
||||
if (!this.stunned)
|
||||
{
|
||||
agent.SetDestination(chair.gameObject.transform.position);
|
||||
Debug.Log("Se setea nuevo destino por silla null");
|
||||
}
|
||||
} else if (!targetChair.Equals(gameController.freeChairs[selectedIndex]))
|
||||
{
|
||||
ChairsChairController chair = gameController.freeChairs[selectedIndex];
|
||||
targetChair = chair;
|
||||
if (!this.stunned)
|
||||
{
|
||||
agent.SetDestination(chair.gameObject.transform.position);
|
||||
Debug.Log("Se setea nuevo destino por nueva silla mas cercana");
|
||||
}
|
||||
}
|
||||
}
|
||||
yield return new WaitForSecondsRealtime(findNewChairDelay);
|
||||
}
|
||||
}
|
||||
|
||||
private float GetPathLength(NavMeshPath path)
|
||||
{
|
||||
float lng = 0.0f;
|
||||
|
||||
if ((path.status != NavMeshPathStatus.PathInvalid))
|
||||
{
|
||||
for (int i = 1; i < path.corners.Length; ++i)
|
||||
{
|
||||
lng += Vector3.Distance(path.corners[i - 1], path.corners[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return lng;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (actualStunCoolDown != 0)
|
||||
{
|
||||
actualStunCoolDown -= Time.deltaTime;
|
||||
if (actualStunCoolDown < 0)
|
||||
{
|
||||
actualStunCoolDown = 0;
|
||||
}
|
||||
}
|
||||
if (stunned || paused)
|
||||
{
|
||||
agent.SetDestination(this.transform.position);
|
||||
} else
|
||||
{
|
||||
anim.SetFloat("VelocityX", agent.velocity.x);
|
||||
anim.SetFloat("VelocityY", agent.velocity.z);
|
||||
}
|
||||
/*
|
||||
if (targetChair != null && !stunned && canMove)
|
||||
{
|
||||
var targetRotation = Quaternion.LookRotation(targetChair.position - transform.position);
|
||||
|
||||
// Smoothly rotate towards the target point.
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 3 * Time.deltaTime);
|
||||
|
||||
Vector3 targetPos = new Vector3(targetChair.position.x, 0f, targetChair.position.z);
|
||||
|
||||
transform.position = Vector3.MoveTowards(transform.position, targetPos, speed * Time.deltaTime);
|
||||
}else if (stunned)
|
||||
{
|
||||
if (moveLeft)
|
||||
{
|
||||
controller.Move(Vector3.left * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (moveRight)
|
||||
{
|
||||
controller.Move(Vector3.right * Time.deltaTime);
|
||||
}
|
||||
|
||||
StartCoroutine(StopStunned());
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void ChooseNewChair()
|
||||
{
|
||||
targetChair = null;
|
||||
for (int i = 0; i < gameController.freeChairs.Count; i++)
|
||||
{
|
||||
if (!gameController.freeChairs[i].GetComponent<ChairsChairController>().occupied)
|
||||
{
|
||||
targetChair = gameController.freeChairs[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetEnemy()
|
||||
{
|
||||
//agent.enabled = false;
|
||||
agent.Warp(startPosition);
|
||||
transform.rotation = new Quaternion(0, 0, 0, 0);
|
||||
//agent.enabled = true;
|
||||
//enemy.gameObject.SetActive(true);
|
||||
//this.sat = false;
|
||||
this.stunned = false;
|
||||
this.targetChair = null;
|
||||
SetNewTargetChair();
|
||||
}
|
||||
|
||||
private void ResetAnimation()
|
||||
{
|
||||
anim.SetFloat("VelocityX", 0);
|
||||
anim.SetFloat("VelocityY", 0);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
|
||||
if (other.CompareTag("Enemy"))
|
||||
{
|
||||
ChairsEnemyController enemy = other.GetComponent<ChairsEnemyController>();
|
||||
DecideStun(enemy);
|
||||
}
|
||||
|
||||
else if (other.CompareTag("Player"))
|
||||
{
|
||||
ChairsPlayerController enemy = other.GetComponent<ChairsPlayerController>();
|
||||
DecideStun(enemy);
|
||||
}
|
||||
|
||||
if (other.CompareTag("Chair"))
|
||||
{
|
||||
ChairsChairController chair = other.GetComponent<ChairsChairController>();
|
||||
if (!chair.occupied)
|
||||
{
|
||||
this.sat = true;
|
||||
chair.AssignSeat();
|
||||
ResetAnimation();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void DecideStun(ChairsEnemyController enemy)
|
||||
{
|
||||
float decision = Random.Range(0, 3);
|
||||
if (decision < 1)
|
||||
{
|
||||
if (actualStunCoolDown == 0 && !enemy.stunned) {
|
||||
Stun(enemy);
|
||||
actualStunCoolDown = stunCoolDown;
|
||||
}
|
||||
}
|
||||
}
|
||||
private void DecideStun(ChairsPlayerController enemy)
|
||||
{
|
||||
float decision = Random.Range(0, 5);
|
||||
if (decision < 1)
|
||||
{
|
||||
if (actualStunCoolDown == 0 && !enemy.stunned)
|
||||
{
|
||||
Stun(enemy);
|
||||
actualStunCoolDown = stunCoolDown;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Stun(ChairsEnemyController enemy)
|
||||
{
|
||||
enemy.StunMyself();
|
||||
}
|
||||
|
||||
private void Stun(ChairsPlayerController enemy)
|
||||
{
|
||||
enemy.StunMyself();
|
||||
}
|
||||
|
||||
public void StunMyself()
|
||||
{
|
||||
stunned = true;
|
||||
StartCoroutine(StunMyselfCoroutine());
|
||||
}
|
||||
|
||||
private IEnumerator StunMyselfCoroutine()
|
||||
{
|
||||
|
||||
Debug.Log("Me stuneo " + this.gameObject.name);
|
||||
agent.isStopped = true;
|
||||
ResetAnimation();
|
||||
yield return new WaitForSecondsRealtime(stunDuration);
|
||||
Debug.Log("Me termino el stuneo " + this.gameObject.name);
|
||||
agent.isStopped = false;
|
||||
stunned = false;
|
||||
this.targetChair = null;
|
||||
SetNewTargetChair();
|
||||
}
|
||||
/*
|
||||
public void ResetAnim()
|
||||
{
|
||||
anim.SetFloat("VelocityX", 0);
|
||||
anim.SetFloat("VelocityY", 0);
|
||||
}*/
|
||||
|
||||
public void Loose()
|
||||
{
|
||||
anim.SetTrigger("DieWithoutGettingUp");
|
||||
}
|
||||
|
||||
|
||||
}
|
11
Assets/Scripts/ChairsGame/ChairsEnemyController.cs.meta
Normal file
11
Assets/Scripts/ChairsGame/ChairsEnemyController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 60be722b62bd545429a6be8d9a1a9125
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
374
Assets/Scripts/ChairsGame/ChairsGameController.cs
Normal file
374
Assets/Scripts/ChairsGame/ChairsGameController.cs
Normal file
|
@ -0,0 +1,374 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using Cinemachine;
|
||||
using System.Threading;
|
||||
|
||||
public class ChairsGameController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] ScenesTransitionController scenesTransition;
|
||||
[SerializeField] CinemachineVirtualCamera cameraCutscene;
|
||||
[SerializeField] CinemachineVirtualCamera cameraGame;
|
||||
[SerializeField] CinemachineVirtualCamera cameraEndOfRound;
|
||||
|
||||
[SerializeField] float initialCinematicVelocity;
|
||||
|
||||
[SerializeField] GameObject tutorialPanel;
|
||||
[SerializeField] GameObject countdownPanel;
|
||||
[SerializeField] GameObject gameOverPanel;
|
||||
|
||||
|
||||
[SerializeField] float timeBetweenRoundsAfterCam;
|
||||
[SerializeField] float velocityCamBetweenRounds;
|
||||
|
||||
[SerializeField] NavMeshSurface surface;
|
||||
|
||||
[SerializeField] GameObject[] obstacles1;
|
||||
[SerializeField] GameObject[] obstacles2;
|
||||
[SerializeField] GameObject[] obstacles3;
|
||||
[SerializeField] GameObject[] obstacles4;
|
||||
|
||||
|
||||
[SerializeField] ChairsChairController[] chairs;
|
||||
/*[HideInInspector]*/
|
||||
public List<ChairsChairController> chairsPlaying;
|
||||
/*[HideInInspector]*/
|
||||
public List<ChairsChairController> freeChairs;
|
||||
|
||||
[SerializeField] ChairsEnemyController[] enemies;
|
||||
/*[HideInInspector]*/
|
||||
public List<ChairsEnemyController> enemiesPlaying;
|
||||
|
||||
[SerializeField] ChairsPlayerController player;
|
||||
|
||||
[SerializeField] int numberOfRounds;
|
||||
[SerializeField] private int actualRound = 1;
|
||||
|
||||
private bool prueba = false;
|
||||
|
||||
bool scoreDistributed;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
chairsPlaying = new List<ChairsChairController>(chairs);
|
||||
enemiesPlaying = new List<ChairsEnemyController>(enemies);
|
||||
StartCoroutine(AudioManager.instance.FadeIn("transicion", 1));
|
||||
PrepareMap();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
}
|
||||
|
||||
public void StartGame()
|
||||
{
|
||||
StartCoroutine(BeforeStartGame());
|
||||
}
|
||||
|
||||
private IEnumerator BeforeStartGame()
|
||||
{
|
||||
//Fin Cinematica
|
||||
yield return new WaitForSecondsRealtime(0.5f);
|
||||
countdownPanel.SetActive(true);
|
||||
StartCoroutine(AudioManager.instance.FadeOut("transicion", 1));
|
||||
StartCoroutine(AudioManager.instance.FadeIn("03_sillas", 1));
|
||||
yield return new WaitForSecondsRealtime(4f);
|
||||
//tutorialPanel.SetActive(false);
|
||||
countdownPanel.SetActive(false);
|
||||
AudioManager.instance.PlayOneShot("SFX_silbato");
|
||||
SetChairs();
|
||||
StartEnemies();
|
||||
|
||||
InitRound();
|
||||
|
||||
}
|
||||
|
||||
private void StartEnemies()
|
||||
{
|
||||
foreach (ChairsEnemyController enemy in enemies)
|
||||
{
|
||||
enemy.InitGame();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitRound()
|
||||
{
|
||||
PausePlayers(false);
|
||||
}
|
||||
|
||||
private void ResetMap()
|
||||
{
|
||||
foreach (GameObject obstacle in obstacles1)
|
||||
{
|
||||
if (!obstacle.activeSelf)
|
||||
{
|
||||
obstacle.SetActive(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach (GameObject obstacle in obstacles2)
|
||||
{
|
||||
if (!obstacle.activeSelf)
|
||||
{
|
||||
obstacle.SetActive(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach (GameObject obstacle in obstacles3)
|
||||
{
|
||||
if (!obstacle.activeSelf)
|
||||
{
|
||||
obstacle.SetActive(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach (GameObject obstacle in obstacles4)
|
||||
{
|
||||
if (!obstacle.activeSelf)
|
||||
{
|
||||
obstacle.SetActive(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void PrepareMap()
|
||||
{
|
||||
ResetMap();
|
||||
int obstacleToEliminate = Random.Range(0, obstacles1.Length);
|
||||
obstacles1[obstacleToEliminate].SetActive(false);
|
||||
obstacleToEliminate = Random.Range(0, obstacles2.Length);
|
||||
obstacles2[obstacleToEliminate].SetActive(false);
|
||||
obstacleToEliminate = Random.Range(0, obstacles3.Length);
|
||||
obstacles3[obstacleToEliminate].SetActive(false);
|
||||
obstacleToEliminate = Random.Range(0, obstacles4.Length);
|
||||
obstacles4[obstacleToEliminate].SetActive(false);
|
||||
//surface.BuildNavMesh();
|
||||
}
|
||||
|
||||
private void SetChairs()
|
||||
{
|
||||
freeChairs = new List<ChairsChairController>(chairsPlaying);
|
||||
}
|
||||
|
||||
private void SetEnemies()
|
||||
{
|
||||
enemiesPlaying = new List<ChairsEnemyController>(enemies);
|
||||
}
|
||||
|
||||
public void OccupyChair(ChairsChairController chair)
|
||||
{
|
||||
freeChairs.Remove(chair);
|
||||
if (freeChairs.Count == 0)
|
||||
{
|
||||
GameOver();
|
||||
}
|
||||
}
|
||||
|
||||
private void GameOver()
|
||||
{
|
||||
Debug.Log("Fin de ronda");
|
||||
if (!player.sat)
|
||||
{
|
||||
player.sat = false;
|
||||
Debug.Log("Termina porque player no sentado, ronda: " + actualRound);
|
||||
FinishGame();
|
||||
return;
|
||||
}
|
||||
if (actualRound < numberOfRounds)
|
||||
{
|
||||
player.sat = false;
|
||||
actualRound++;
|
||||
StartCoroutine(WaitEndOfRound());
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Termina por rondas");
|
||||
FinishGame();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator WaitEndOfRound()
|
||||
{
|
||||
//AudioManager.instance.Play("transicion");
|
||||
LooseEnemies(); //Para animacion
|
||||
PausePlayers(true);
|
||||
cameraGame.gameObject.SetActive(false);
|
||||
cameraEndOfRound.gameObject.SetActive(true);
|
||||
Vector3 initialPosOfCamera = cameraEndOfRound.transform.position;
|
||||
yield return new WaitForSecondsRealtime(timeBetweenRoundsAfterCam);
|
||||
PrepareMap();
|
||||
//yield return new WaitForSecondsRealtime(timeBetweenRoundsAfterCam/2);
|
||||
float i = 0;
|
||||
while (i < 1.5)
|
||||
{
|
||||
i += Time.deltaTime;
|
||||
cameraEndOfRound.transform.Translate(Vector3.back * Time.deltaTime * velocityCamBetweenRounds, Space.World);
|
||||
yield return null;
|
||||
}
|
||||
//yield return new WaitForSecondsRealtime(timeBetweenRoundsAfterCam/2);
|
||||
ResetPlayersPosition();
|
||||
EliminatePlayersAndChairs();
|
||||
i = 0;
|
||||
while (i < 1)
|
||||
{
|
||||
i += Time.deltaTime;
|
||||
cameraEndOfRound.transform.Translate(Vector3.back * Time.deltaTime * velocityCamBetweenRounds, Space.World);
|
||||
yield return null;
|
||||
}
|
||||
cameraGame.gameObject.SetActive(true);
|
||||
cameraEndOfRound.gameObject.SetActive(false);
|
||||
countdownPanel.SetActive(true);
|
||||
yield return new WaitForSecondsRealtime(4);
|
||||
cameraEndOfRound.transform.position = initialPosOfCamera;
|
||||
countdownPanel.SetActive(false);
|
||||
PausePlayers(false);
|
||||
player.sat = false;
|
||||
foreach (ChairsEnemyController enemy in enemiesPlaying)
|
||||
{
|
||||
enemy.SetNewTargetChair();
|
||||
}
|
||||
}
|
||||
|
||||
private void PausePlayers(bool mode)
|
||||
{
|
||||
|
||||
player.paused = mode;
|
||||
foreach (ChairsEnemyController enemy in enemiesPlaying)
|
||||
{
|
||||
enemy.paused = mode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void LooseEnemies()
|
||||
{
|
||||
foreach (ChairsEnemyController enemy in enemiesPlaying)
|
||||
{
|
||||
if (!enemy.sat)
|
||||
{
|
||||
enemy.Loose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetPlayersPosition()
|
||||
{
|
||||
ResetPlayer();
|
||||
foreach (ChairsEnemyController enemy in enemiesPlaying)
|
||||
{
|
||||
//ResetEnemy(enemy);
|
||||
enemy.ResetEnemy();
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetPlayer()
|
||||
{
|
||||
//Debug.Log("Esta en:" + player.transform.position + " y quiere ir a " + player.startPosition);
|
||||
// Debug.Log("Reseteo del player");
|
||||
//player.sat = false;
|
||||
CharacterController charController = player.GetComponent<CharacterController>();
|
||||
charController.enabled = false;
|
||||
player.transform.position = player.startPosition;
|
||||
player.transform.rotation = new Quaternion(0, 0, 0, 0);
|
||||
charController.enabled = true;
|
||||
//player.gameObject.SetActive(true);
|
||||
player.stunned = false;
|
||||
player.ResetAnim();
|
||||
//player.sat = false;
|
||||
//Debug.Log("Ha llegado a: " + player.transform.position);
|
||||
}
|
||||
|
||||
private void ResetEnemy(ChairsEnemyController enemy)
|
||||
{
|
||||
//enemy.gameObject.SetActive(false);
|
||||
NavMeshAgent agent = enemy.GetComponent<NavMeshAgent>();
|
||||
//agent.enabled = false;
|
||||
enemy.transform.position = enemy.startPosition;
|
||||
player.transform.rotation = new Quaternion(0, 0, 0, 0);
|
||||
//agent.enabled = true;
|
||||
//enemy.gameObject.SetActive(true);
|
||||
enemy.sat = false;
|
||||
enemy.stunned = false;
|
||||
//enemy.SetNewTargetChair();
|
||||
}
|
||||
|
||||
private void EliminatePlayersAndChairs()
|
||||
{
|
||||
int indexToEliminate = -1;
|
||||
for (int i = 0; i < enemiesPlaying.Count; i++)
|
||||
{
|
||||
if (!enemiesPlaying[i].sat)
|
||||
{
|
||||
indexToEliminate = i;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
enemiesPlaying[i].sat = false;
|
||||
}
|
||||
}
|
||||
ChairsEnemyController enemy = enemiesPlaying[indexToEliminate];
|
||||
enemy.gameObject.SetActive(false);
|
||||
enemiesPlaying.RemoveAt(indexToEliminate);
|
||||
player.sat = false;
|
||||
for (int i = 0; i < chairsPlaying.Count; i++)
|
||||
{
|
||||
chairsPlaying[i].occupied = false;
|
||||
}
|
||||
|
||||
indexToEliminate = Random.Range(0, chairsPlaying.Count);
|
||||
ChairsChairController silla = chairsPlaying[indexToEliminate];
|
||||
silla.gameObject.SetActive(false);
|
||||
chairsPlaying.RemoveAt(indexToEliminate);
|
||||
SetChairs();
|
||||
}
|
||||
|
||||
private void FinishGame()
|
||||
{
|
||||
Debug.Log("Fin de partida");
|
||||
//Ver en que ronda estaba cuando se perdio
|
||||
//Si no es el la ultima, calcular tu posicion e inventar las de los que quedan
|
||||
//Si es la ultima, ver si has ganado o perdido
|
||||
|
||||
StartCoroutine(AudioManager.instance.FadeOut("03_sillas", 1));
|
||||
|
||||
if (player.sat)
|
||||
{
|
||||
player.paused = true;
|
||||
ReturnToMenu(player.gameObject.GetComponent<CharacterIdController>().CharacterId);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.Loose();
|
||||
if (BetweenScenePass.instance && BetweenScenePass.instance.NpcCharacterId.Count > 0)
|
||||
ReturnToMenu(BetweenScenePass.instance.NpcCharacterId[Random.Range(0, BetweenScenePass.instance.NpcCharacterId.Count - 1)]);
|
||||
else
|
||||
ReturnToMenu(3);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (prueba)
|
||||
{
|
||||
//Debug.Log(player.transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
void ReturnToMenu(int winner)
|
||||
{
|
||||
if (!scoreDistributed)
|
||||
{
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Chairs,
|
||||
winner,
|
||||
scenesTransition));
|
||||
|
||||
scoreDistributed = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/ChairsGame/ChairsGameController.cs.meta
Normal file
11
Assets/Scripts/ChairsGame/ChairsGameController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3535fe51bf2070241adec146ddcb24db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
267
Assets/Scripts/ChairsGame/ChairsPlayerController.cs
Normal file
267
Assets/Scripts/ChairsGame/ChairsPlayerController.cs
Normal file
|
@ -0,0 +1,267 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ChairsPlayerController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] Animator anim;
|
||||
[SerializeField] CharacterController controller = default;
|
||||
[SerializeField] Transform cam = default;
|
||||
[SerializeField] ChairsGameController gameController;
|
||||
|
||||
[SerializeField] float minSpeed;
|
||||
[SerializeField] float maxSpeed;
|
||||
[SerializeField] float aceleration;
|
||||
[SerializeField] float speed = 6;
|
||||
|
||||
[SerializeField, Range(0, 2f)] float turnSmoothTime = .1f;
|
||||
float turnSmoothVelocity;
|
||||
|
||||
[Header("Jump")]
|
||||
[SerializeField, Min(0)] float gravity = 15f;
|
||||
[SerializeField] float jumpHeight = 3f;
|
||||
[SerializeField, Range(0, .5f)] float jumpDelay = .5f;
|
||||
Vector3 velocity;
|
||||
|
||||
[SerializeField] Transform groundCheck = default;
|
||||
[SerializeField, Range(0, .5f)] float groundDistance = .4f;
|
||||
[SerializeField] LayerMask groundMask = -1;
|
||||
bool isGrounded;
|
||||
|
||||
[SerializeField, Range(0f, .3f)] float jumpPressedRememberTime = .2f;
|
||||
float jumpPressedRemember;
|
||||
|
||||
[Header("Randomize Target X")]
|
||||
[SerializeField] float randomX = 0;
|
||||
[SerializeField] float randomZ = 0;
|
||||
|
||||
|
||||
[SerializeField] float stunDuration;
|
||||
private float actualStunCoolDown;
|
||||
[SerializeField] private float stunCoolDown;
|
||||
|
||||
/*[HideInInspector]*/
|
||||
public Vector3 startPosition;
|
||||
|
||||
bool randomMove = false;
|
||||
|
||||
/*[HideInInspector]*/
|
||||
public bool sat = false;
|
||||
|
||||
public bool paused = false;
|
||||
|
||||
private float lastSped;
|
||||
private float lastHorizontal;
|
||||
private float lastVertical;
|
||||
private Vector3 lastDir;
|
||||
|
||||
[SerializeField, Range(0, 1f)] float stepsInterval = .35f;
|
||||
float currentStepTime;
|
||||
|
||||
Vector3 randomDirection;
|
||||
|
||||
/*
|
||||
Vector3[] directions = {
|
||||
Vector3.right,
|
||||
Vector3.left,
|
||||
Vector3.back
|
||||
};
|
||||
*/
|
||||
|
||||
[HideInInspector] public bool stunned = false;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
//Cursor.lockState = CursorLockMode.Locked;
|
||||
//StartCoroutine(SetRandomDirection());
|
||||
startPosition = this.transform.position;
|
||||
|
||||
anim = GetComponent<CharacterIdController>().SetPlayerCustom();
|
||||
}
|
||||
|
||||
/*
|
||||
IEnumerator SetRandomDirection()
|
||||
{
|
||||
randomMove = true;
|
||||
randomDirection = directions[Random.Range(0, directions.Length)];
|
||||
|
||||
yield return new WaitForSeconds(Random.Range(0.5f, 1f));
|
||||
|
||||
randomMove = false;
|
||||
|
||||
yield return new WaitForSeconds(Random.Range(1f, 2f));
|
||||
|
||||
StartCoroutine(SetRandomDirection());
|
||||
}*/
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (!paused)
|
||||
{
|
||||
if (!sat && !stunned)
|
||||
{
|
||||
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
|
||||
|
||||
if (isGrounded && velocity.y < 0)
|
||||
{
|
||||
velocity.y = -2f;
|
||||
}
|
||||
|
||||
float horizontal = Input.GetAxisRaw("Horizontal");
|
||||
float vertical = Input.GetAxisRaw("Vertical");
|
||||
|
||||
|
||||
Vector3 direction = new Vector3(horizontal, 0, vertical).normalized;
|
||||
|
||||
if (direction.magnitude >= .1f)
|
||||
{
|
||||
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
|
||||
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
|
||||
|
||||
//transform.rotation = Quaternion.Euler(0f, angle, 0f);
|
||||
|
||||
Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
|
||||
|
||||
if (randomMove)
|
||||
{
|
||||
moveDir = Quaternion.Euler(0f, targetAngle, 0f) * randomDirection;
|
||||
}
|
||||
|
||||
moveDir = moveDir.normalized;
|
||||
/*moveDir.x += randomX;
|
||||
moveDir.z += randomZ;*/
|
||||
if (speed < maxSpeed)
|
||||
{
|
||||
speed += aceleration * Time.deltaTime;
|
||||
}
|
||||
|
||||
lastDir = moveDir;
|
||||
lastSped = speed;
|
||||
|
||||
controller.Move(moveDir * speed * Time.deltaTime);
|
||||
|
||||
currentStepTime += Time.deltaTime;
|
||||
if (currentStepTime >= stepsInterval){
|
||||
AudioManager.instance.PlayOneShot("SFX_paso" + Random.Range(1, 6), true);
|
||||
currentStepTime = 0;
|
||||
}
|
||||
|
||||
anim.SetFloat("VelocityX", horizontal);
|
||||
anim.SetFloat("VelocityY", vertical);
|
||||
} else
|
||||
{
|
||||
ResetAnim();
|
||||
}
|
||||
|
||||
jumpPressedRemember -= Time.deltaTime;
|
||||
if (Input.GetButtonDown("Jump"))
|
||||
{
|
||||
jumpPressedRemember = jumpPressedRememberTime;
|
||||
}
|
||||
|
||||
if (jumpPressedRemember > 0f && isGrounded)
|
||||
{
|
||||
StartCoroutine(Jump(jumpDelay));
|
||||
jumpPressedRemember = 0;
|
||||
}
|
||||
|
||||
velocity.y -= gravity * Time.deltaTime;
|
||||
controller.Move(velocity * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (actualStunCoolDown != 0)
|
||||
{
|
||||
actualStunCoolDown -= Time.deltaTime;
|
||||
if (actualStunCoolDown < 0)
|
||||
{
|
||||
actualStunCoolDown = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator Jump(float delay)
|
||||
{
|
||||
yield return new WaitForSeconds(delay);
|
||||
velocity.y = Mathf.Sqrt(jumpHeight * 2f * gravity);
|
||||
jumpPressedRemember = 0;
|
||||
StopCoroutine("Jump");
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Chair"))
|
||||
{
|
||||
ChairsChairController chair = other.GetComponent<ChairsChairController>();
|
||||
if (!chair.occupied)
|
||||
{
|
||||
this.sat = true;
|
||||
chair.AssignSeat();
|
||||
ResetAnim();
|
||||
AudioManager.instance.PlayOneShot("SFX_campanillas");
|
||||
}
|
||||
}
|
||||
|
||||
if (other.CompareTag("Enemy"))
|
||||
{
|
||||
ChairsEnemyController enemy = other.GetComponent<ChairsEnemyController>();
|
||||
DecideStun(enemy);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void DecideStun(ChairsEnemyController enemy)
|
||||
{
|
||||
float decision = Random.Range(0, 3);
|
||||
if (decision < 1)
|
||||
{
|
||||
if (actualStunCoolDown == 0 && !enemy.stunned)
|
||||
{
|
||||
Stun(enemy);
|
||||
actualStunCoolDown = stunCoolDown;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Loose()
|
||||
{
|
||||
anim.SetTrigger("DieWithoutGettingUp");
|
||||
paused = true;
|
||||
}
|
||||
|
||||
public void ResetAnim()
|
||||
{
|
||||
anim.SetFloat("VelocityX", 0);
|
||||
anim.SetFloat("VelocityY", 0);
|
||||
}
|
||||
|
||||
private void Stun(ChairsEnemyController enemy)
|
||||
{
|
||||
enemy.StunMyself();
|
||||
}
|
||||
|
||||
public void StunMyself()
|
||||
{
|
||||
stunned = true;
|
||||
StartCoroutine(StunMyselfCoroutine());
|
||||
}
|
||||
|
||||
private IEnumerator StunMyselfCoroutine()
|
||||
{
|
||||
ResetAnim();
|
||||
yield return new WaitForSecondsRealtime(stunDuration);
|
||||
stunned = false;
|
||||
//anim.SetBool("Stunned", false);
|
||||
}
|
||||
|
||||
/*
|
||||
void OnDrawGizmos()
|
||||
{
|
||||
if (groundCheck != null)
|
||||
{
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireSphere(groundCheck.position, groundDistance);
|
||||
}
|
||||
}*/
|
||||
}
|
11
Assets/Scripts/ChairsGame/ChairsPlayerController.cs.meta
Normal file
11
Assets/Scripts/ChairsGame/ChairsPlayerController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e9520692f050c1044bfc651b6931806e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/CharacterSelection.meta
Normal file
8
Assets/Scripts/CharacterSelection.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e9ed6bb589c7cd848ab32c09c513aebe
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
140
Assets/Scripts/CharacterSelection/CharSelCharacterController.cs
Normal file
140
Assets/Scripts/CharacterSelection/CharSelCharacterController.cs
Normal file
|
@ -0,0 +1,140 @@
|
|||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
|
||||
public class CharSelCharacterController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] public string charName;
|
||||
public string phrase;
|
||||
[SerializeField] float speed;
|
||||
[SerializeField] float rotationSpeed;
|
||||
|
||||
|
||||
[SerializeField] Transform spawnPointLeft;
|
||||
[SerializeField] Transform spawnPointRight;
|
||||
[SerializeField] Transform spawnPointCenter;
|
||||
|
||||
[SerializeField] TextMeshProUGUI phraseText;
|
||||
[SerializeField] GameObject phrasePanel;
|
||||
|
||||
|
||||
[SerializeField] public Animator anim;
|
||||
|
||||
bool canWalk;
|
||||
bool moveLeft;
|
||||
bool moveRight;
|
||||
|
||||
bool stopAtCenter;
|
||||
bool restoreRotation;
|
||||
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
canWalk = false;
|
||||
moveLeft = false;
|
||||
moveRight = false;
|
||||
moveRight = false;
|
||||
transform.localRotation = Quaternion.Euler(0, 180, 0);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (canWalk)
|
||||
{
|
||||
|
||||
anim.SetFloat("Dance", 0f);
|
||||
|
||||
Quaternion targetRotation = Quaternion.identity;
|
||||
Vector3 targetPosition = Vector3.zero;
|
||||
|
||||
if (moveLeft)
|
||||
{
|
||||
targetRotation = Quaternion.LookRotation(spawnPointLeft.localPosition - transform.localPosition);
|
||||
targetPosition = new Vector3(spawnPointLeft.localPosition.x, 0f, 0f);
|
||||
}
|
||||
else if (moveRight)
|
||||
{
|
||||
targetRotation = Quaternion.LookRotation(spawnPointRight.localPosition - transform.localPosition);
|
||||
targetPosition = new Vector3(spawnPointRight.localPosition.x, 0f, 0f);
|
||||
}
|
||||
|
||||
if (stopAtCenter)
|
||||
{
|
||||
targetPosition = new Vector3(spawnPointCenter.localPosition.x, 0f, 0f);
|
||||
}
|
||||
|
||||
transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotation, rotationSpeed * Time.deltaTime);
|
||||
transform.localPosition = Vector3.MoveTowards(transform.localPosition, targetPosition, speed * Time.deltaTime);
|
||||
|
||||
anim.SetFloat("VelocityY", 1f);
|
||||
|
||||
|
||||
if (stopAtCenter && (Mathf.Round(transform.localPosition.x * 10f) / 10f) == spawnPointCenter.localPosition.x)
|
||||
{
|
||||
canWalk = false;
|
||||
moveLeft = false;
|
||||
moveRight = false;
|
||||
stopAtCenter = false;
|
||||
restoreRotation = true;
|
||||
|
||||
phraseText.text = phrase;
|
||||
phrasePanel.GetComponent<Animator>().SetBool("visible", true);
|
||||
|
||||
anim.SetFloat("VelocityY", 0f);
|
||||
anim.SetFloat("Dance", GetComponent<CharacterIdController>().Dance);
|
||||
}
|
||||
else if(!stopAtCenter && (transform.localPosition.x == spawnPointRight.localPosition.x || transform.localPosition.x == spawnPointLeft.localPosition.x))
|
||||
{
|
||||
canWalk = false;
|
||||
moveLeft = false;
|
||||
moveRight = false;
|
||||
gameObject.SetActive(false);
|
||||
|
||||
anim.SetFloat("VelocityY", 0f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (restoreRotation)
|
||||
{
|
||||
transform.localRotation = Quaternion.Slerp(transform.localRotation, Quaternion.Euler(0, 180, 0), rotationSpeed * Time.deltaTime);
|
||||
|
||||
if (transform.localRotation.eulerAngles.y > 160 && transform.localRotation.eulerAngles.y < 200)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (transform.localRotation == Quaternion.Euler(0, 180, 0))
|
||||
{
|
||||
restoreRotation = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void WalkLeft(bool stopCharAtCenter)
|
||||
{
|
||||
restoreRotation = false;
|
||||
|
||||
canWalk = true;
|
||||
moveLeft = true;
|
||||
|
||||
stopAtCenter = stopCharAtCenter;
|
||||
}
|
||||
|
||||
public void WalkRight(bool stopCharAtCenter)
|
||||
{
|
||||
restoreRotation = false;
|
||||
|
||||
canWalk = true;
|
||||
moveRight = true;
|
||||
|
||||
stopAtCenter = stopCharAtCenter;
|
||||
}
|
||||
|
||||
void StopRestoringRotation()
|
||||
{
|
||||
restoreRotation = false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 40044a5789dc33e4095a2744d9b3b75e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
179
Assets/Scripts/CharacterSelection/CharSelSelectionController.cs
Normal file
179
Assets/Scripts/CharacterSelection/CharSelSelectionController.cs
Normal file
|
@ -0,0 +1,179 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using Cinemachine;
|
||||
|
||||
public class CharSelSelectionController : MonoBehaviour
|
||||
{
|
||||
[Space(10)]
|
||||
[SerializeField] GameObject levelNPCs;
|
||||
[SerializeField] List<GameObject> npcList;
|
||||
|
||||
[Space(10)]
|
||||
[SerializeField] List<GameObject> characterList;
|
||||
[SerializeField] GameObject selectedCharacter;
|
||||
|
||||
[Space(10)]
|
||||
[SerializeField] Transform spawnPointLeft;
|
||||
[SerializeField] Transform spawnPointRight;
|
||||
|
||||
[Space(10)]
|
||||
[SerializeField] TextMeshProUGUI phraseText;
|
||||
[SerializeField] GameObject phrasePanel;
|
||||
[SerializeField] GameObject nextButton;
|
||||
[SerializeField] GameObject prevButton;
|
||||
[SerializeField] GameObject playButton;
|
||||
[SerializeField] GameObject characters;
|
||||
[SerializeField] GameObject player;
|
||||
[SerializeField] GameObject trackCamera;
|
||||
[SerializeField] GameObject cam;
|
||||
|
||||
int selectedCharacterIndex = 0;
|
||||
|
||||
bool canSpawnCharacter = true;
|
||||
|
||||
|
||||
void Awake()
|
||||
{
|
||||
selectedCharacter = characterList[selectedCharacterIndex];
|
||||
phraseText.text = selectedCharacter.GetComponent<CharSelCharacterController>().phrase;
|
||||
}
|
||||
|
||||
public void OnPlayClick()
|
||||
{
|
||||
if (canSpawnCharacter)
|
||||
{
|
||||
GameObject.Find("Menu").GetComponent<InvitationController>().OpensConfirmDirectly(selectedCharacter.GetComponent<CharSelCharacterController>().charName);
|
||||
}
|
||||
}
|
||||
|
||||
public void ConfirmPlay()
|
||||
{
|
||||
BetweenScenePass data = BetweenScenePass.instance;
|
||||
CharacterIdController selecterCharacterCustom = selectedCharacter.GetComponent<CharacterIdController>();
|
||||
|
||||
phrasePanel.SetActive(false);
|
||||
nextButton.SetActive(false);
|
||||
prevButton.SetActive(false);
|
||||
playButton.SetActive(false);
|
||||
characters.SetActive(false);
|
||||
levelNPCs.transform.position = new Vector3(levelNPCs.transform.position.x, 0, levelNPCs.transform.position.z);
|
||||
trackCamera.SetActive(false);
|
||||
|
||||
int selectedCharId = selecterCharacterCustom.CharacterId;
|
||||
|
||||
data.PlayerCharacterId = selectedCharId;
|
||||
|
||||
GameObject selectedNPC = null;
|
||||
|
||||
for (int i = 0; i < npcList.Count; i++)
|
||||
{
|
||||
if(npcList[i].GetComponent<CharacterIdController>().CharacterId == selectedCharId)
|
||||
{
|
||||
selectedNPC = npcList[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
data.NpcCharacterId.Add(npcList[i].GetComponent<CharacterIdController>().CharacterId);
|
||||
}
|
||||
}
|
||||
|
||||
player.GetComponent<MenuPlayerMovement>().anim = player.GetComponent<CharacterIdController>().SetPlayerCustom();
|
||||
|
||||
|
||||
player.transform.position = new Vector3(selectedNPC.transform.position.x, 1.08f, selectedNPC.transform.position.z);
|
||||
player.transform.rotation = selectedNPC.transform.rotation;
|
||||
|
||||
selectedNPC.SetActive(false);
|
||||
|
||||
player.SetActive(true);
|
||||
|
||||
|
||||
cam.SetActive(true);
|
||||
|
||||
|
||||
gameObject.SetActive(false);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void OnPrevCharacterClick()
|
||||
{
|
||||
if (canSpawnCharacter && (phrasePanel.transform.localScale.x > 0.5 || phrasePanel.transform.localScale.x < 0.5))
|
||||
{
|
||||
canSpawnCharacter = false;
|
||||
StartCoroutine(MoveCharacter(0));
|
||||
}
|
||||
}
|
||||
|
||||
public void OnNextCharacterClick()
|
||||
{
|
||||
if (canSpawnCharacter && (phrasePanel.transform.localScale.x > 0.5 || phrasePanel.transform.localScale.x < 0.5))
|
||||
{
|
||||
canSpawnCharacter = false;
|
||||
StartCoroutine(MoveCharacter(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UpdateIndex(int direction)
|
||||
{
|
||||
if (selectedCharacterIndex == 0 && direction == 0)
|
||||
{
|
||||
selectedCharacterIndex = characterList.Count - 1;
|
||||
}else if (selectedCharacterIndex == characterList.Count - 1 && direction == 1)
|
||||
{
|
||||
selectedCharacterIndex = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedCharacterIndex += direction == 0 ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateSelectedCharacter(float posX)
|
||||
{
|
||||
selectedCharacter = characterList[selectedCharacterIndex];
|
||||
selectedCharacter.transform.localPosition = new Vector3(posX, 0, selectedCharacter.transform.localPosition.z);
|
||||
selectedCharacter.SetActive(true);
|
||||
}
|
||||
|
||||
void EmptyCharacterPhrase()
|
||||
{
|
||||
phraseText.text = " ";
|
||||
phrasePanel.GetComponent<Animator>().SetBool("visible", false);
|
||||
}
|
||||
|
||||
IEnumerator MoveCharacter(int direction)
|
||||
{
|
||||
EmptyCharacterPhrase();
|
||||
|
||||
yield return new WaitForSeconds(0.15f);
|
||||
|
||||
if (direction == 0)
|
||||
selectedCharacter.GetComponent<CharSelCharacterController>().WalkLeft(false);
|
||||
else if(direction == 1)
|
||||
selectedCharacter.GetComponent<CharSelCharacterController>().WalkRight(false);
|
||||
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
UpdateIndex(direction);
|
||||
|
||||
if (direction == 0)
|
||||
{
|
||||
UpdateSelectedCharacter(spawnPointRight.transform.localPosition.x);
|
||||
selectedCharacter.GetComponent<CharSelCharacterController>().WalkLeft(true);
|
||||
}
|
||||
else if (direction == 1)
|
||||
{
|
||||
UpdateSelectedCharacter(spawnPointLeft.transform.localPosition.x);
|
||||
selectedCharacter.GetComponent<CharSelCharacterController>().WalkRight(true);
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
|
||||
canSpawnCharacter = true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 41cead2536b82f84caeea430b223366f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
101
Assets/Scripts/CharacterSelection/CharacterIdController.cs
Normal file
101
Assets/Scripts/CharacterSelection/CharacterIdController.cs
Normal file
|
@ -0,0 +1,101 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class CharacterIdController : MonoBehaviour
|
||||
{
|
||||
public int characterId;
|
||||
[SerializeField] int dance;
|
||||
[SerializeField] Animator anim;
|
||||
|
||||
[SerializeField] List<GameObject> models;
|
||||
|
||||
public int CharacterId { get => characterId; set => characterId = value; }
|
||||
public int Dance { get => dance; set => dance = value; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if(gameObject.CompareTag("Player"))
|
||||
anim = GetComponent<CharacterIdController>().SetPlayerCustom();
|
||||
|
||||
if (characterId > -1)
|
||||
{
|
||||
if (Dance > 0)
|
||||
{
|
||||
DanceDance(Dance);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void DanceDance(int _dance)
|
||||
{
|
||||
Dance = _dance;
|
||||
anim.SetFloat("Dance", Dance);
|
||||
}
|
||||
|
||||
public Animator SetRandomNpcCustom()
|
||||
{
|
||||
BetweenScenePass data = BetweenScenePass.instance;
|
||||
|
||||
if (data && data.NpcCharacterId.Count > 0)
|
||||
{
|
||||
characterId = data.NpcCharacterId[Random.Range(0, data.NpcCharacterId.Count-1)];
|
||||
}
|
||||
else
|
||||
{
|
||||
characterId = 5;
|
||||
}
|
||||
|
||||
return ActivateModel(characterId);
|
||||
}
|
||||
|
||||
public Animator SetNpcCustom(int npcId)
|
||||
{
|
||||
BetweenScenePass data = BetweenScenePass.instance;
|
||||
|
||||
if (data && data.NpcCharacterId.Count > 0)
|
||||
{
|
||||
if (data.NpcCharacterId.Contains(npcId))
|
||||
characterId = data.NpcCharacterId[data.NpcCharacterId.IndexOf(npcId)];
|
||||
else if (npcId == data.PlayerCharacterId)
|
||||
characterId = data.PlayerCharacterId;
|
||||
}
|
||||
else
|
||||
{
|
||||
characterId = 5;
|
||||
}
|
||||
|
||||
return ActivateModel(npcId);
|
||||
}
|
||||
|
||||
public Animator ActivateModel(int npcId)
|
||||
{
|
||||
|
||||
characterId = npcId;
|
||||
|
||||
models[npcId].SetActive(true);
|
||||
|
||||
anim = models[npcId].GetComponent<Animator>();
|
||||
|
||||
return models[npcId].GetComponent<Animator>();
|
||||
}
|
||||
|
||||
|
||||
public Animator SetPlayerCustom()
|
||||
{
|
||||
BetweenScenePass data = BetweenScenePass.instance;
|
||||
|
||||
if (data && data.PlayerCharacterId > -1)
|
||||
{
|
||||
characterId = data.PlayerCharacterId;
|
||||
}
|
||||
else
|
||||
{
|
||||
characterId = 0;
|
||||
}
|
||||
|
||||
return ActivateModel(characterId);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3fb5599a903e3c849bf5ec998669e1fc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
369
Assets/Scripts/CharacterSelection/InvitationController.cs
Normal file
369
Assets/Scripts/CharacterSelection/InvitationController.cs
Normal file
|
@ -0,0 +1,369 @@
|
|||
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System.Collections;
|
||||
|
||||
public class InvitationController : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] ScenesTransitionController sceneTransition;
|
||||
[SerializeField] GameTutorialControler tutorial;
|
||||
|
||||
[Space(20)]
|
||||
[SerializeField] float showDelay;
|
||||
[SerializeField] float hideDelay;
|
||||
|
||||
[Header("Invitation Panels")]
|
||||
[SerializeField] GameObject leftPanelBack;
|
||||
[SerializeField] GameObject leftPanel;
|
||||
[SerializeField] GameObject rightPanel;
|
||||
|
||||
[Header("Menu Panels")]
|
||||
[SerializeField] GameObject title;
|
||||
[SerializeField] GameObject mainMenu;
|
||||
[SerializeField] GameObject pauseMenu;
|
||||
[SerializeField] GameObject controls;
|
||||
[SerializeField] GameObject options;
|
||||
[SerializeField] GameObject credits;
|
||||
[SerializeField] GameObject confirmationRight;
|
||||
[SerializeField] GameObject confirmationLeft;
|
||||
|
||||
[Space(10)]
|
||||
[SerializeField] TextMeshProUGUI confirmationQuestionRight;
|
||||
[SerializeField] TextMeshProUGUI confirmationQuestionLeft;
|
||||
|
||||
|
||||
[Space(10)]
|
||||
[SerializeField] Animator anim;
|
||||
|
||||
[Space(10)]
|
||||
[SerializeField] bool mainMenuOnBackClick;
|
||||
|
||||
[Header("Player Selector Objects (MAIN MENU ONLY)")]
|
||||
[SerializeField] GameObject characterSelectorController;
|
||||
[SerializeField] GameObject characters;
|
||||
[SerializeField] GameObject npcs;
|
||||
[SerializeField] GameObject panelPhrase;
|
||||
[SerializeField] GameObject nextCharButton;
|
||||
[SerializeField] GameObject prevCharButton;
|
||||
[SerializeField] GameObject playButton;
|
||||
[SerializeField] GameObject backMenuButton;
|
||||
|
||||
[SerializeField] bool pauseIsUp;
|
||||
|
||||
[SerializeField] string confirmTrigger;
|
||||
|
||||
[SerializeField] GameObject lastShowedPanel;
|
||||
|
||||
CursorLockMode cursorLastState;
|
||||
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
if (GameObject.Find("BetweenScenePass") != null)
|
||||
StartCoroutine(StartInvitation());
|
||||
else
|
||||
{
|
||||
MenuShowConfig();
|
||||
options.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator StartInvitation()
|
||||
{
|
||||
yield return new WaitUntil(() => BetweenScenePass.instance != null);
|
||||
MenuShowConfig();
|
||||
options.SetActive(false);
|
||||
}
|
||||
|
||||
void MenuShowConfig()
|
||||
{
|
||||
if (BetweenScenePass.instance && !BetweenScenePass.instance.GameRestarted && mainMenuOnBackClick)
|
||||
mainMenuOnBackClick = false;
|
||||
|
||||
if (mainMenuOnBackClick)
|
||||
{
|
||||
title.SetActive(true);
|
||||
mainMenu.SetActive(true);
|
||||
|
||||
leftPanelBack.SetActive(true);
|
||||
leftPanel.SetActive(true);
|
||||
rightPanel.SetActive(true);
|
||||
|
||||
lastShowedPanel = mainMenu;
|
||||
|
||||
Invoke("HideTitle", 17.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SceneManager.GetActiveScene().name == "EndGame")
|
||||
backMenuButton.SetActive(false);
|
||||
|
||||
pauseMenu.SetActive(true);
|
||||
anim.SetBool("iddle", true);
|
||||
lastShowedPanel = pauseMenu;
|
||||
}
|
||||
|
||||
if (backMenuButton != null)
|
||||
{
|
||||
backMenuButton.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
void HideTitle()
|
||||
{
|
||||
title.SetActive(false);
|
||||
}
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (tutorial == null || tutorial.gameStarted)
|
||||
{
|
||||
if (!mainMenuOnBackClick && Input.GetKeyDown(KeyCode.Escape) && (characterSelectorController == null || !characterSelectorController.activeInHierarchy))
|
||||
{
|
||||
if (pauseIsUp)
|
||||
{
|
||||
Time.timeScale = 1;
|
||||
anim.SetTrigger("pauseDown");
|
||||
Invoke("ReactivatePauseMenuAfterGoDown", 0.2f);
|
||||
|
||||
if (cursorLastState == CursorLockMode.Locked)
|
||||
{
|
||||
Cursor.visible = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
else
|
||||
{
|
||||
Cursor.visible = true;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Time.timeScale = 0;
|
||||
anim.SetTrigger("pauseUp");
|
||||
|
||||
cursorLastState = Cursor.lockState;
|
||||
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
|
||||
pauseIsUp = !pauseIsUp;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ReactivatePauseMenuAfterGoDown()
|
||||
{
|
||||
pauseMenu.SetActive(true);
|
||||
controls.SetActive(false);
|
||||
options.SetActive(false);
|
||||
credits.SetActive(false);
|
||||
confirmationRight.SetActive(false);
|
||||
confirmationLeft.SetActive(false);
|
||||
mainMenu.SetActive(false);
|
||||
|
||||
lastShowedPanel = pauseMenu;
|
||||
|
||||
StopAllCoroutines();
|
||||
}
|
||||
|
||||
public void OnPlayClick()
|
||||
{
|
||||
mainMenuOnBackClick = false;
|
||||
anim.SetTrigger("pauseDown");
|
||||
pauseIsUp = false;
|
||||
|
||||
Invoke("ReactivatePauseMenuAfterGoDown", 0.2f);
|
||||
|
||||
characterSelectorController.SetActive(true);
|
||||
characters.SetActive(true);
|
||||
npcs.transform.position = new Vector3(npcs.transform.position.x, -10, npcs.transform.position.z);
|
||||
panelPhrase.SetActive(true);
|
||||
nextCharButton.SetActive(true);
|
||||
prevCharButton.SetActive(true);
|
||||
playButton.SetActive(true);
|
||||
}
|
||||
|
||||
public void OnResumeClick()
|
||||
{
|
||||
Time.timeScale = 1;
|
||||
anim.SetTrigger("pauseDown");
|
||||
pauseIsUp = false;
|
||||
|
||||
if (cursorLastState == CursorLockMode.Locked)
|
||||
{
|
||||
Cursor.visible = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
else
|
||||
{
|
||||
Cursor.visible = true;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnControlsClick()
|
||||
{
|
||||
StartCoroutine(HidePanel(lastShowedPanel));
|
||||
StartCoroutine(ShowPanel(controls));
|
||||
anim.SetTrigger("rotate");
|
||||
}
|
||||
|
||||
public void OnOptionsClick()
|
||||
{
|
||||
StartCoroutine(HidePanel(lastShowedPanel));
|
||||
StartCoroutine(ShowPanel(options));
|
||||
anim.SetTrigger("rotate");
|
||||
}
|
||||
|
||||
public void OnCreditsClick()
|
||||
{
|
||||
StartCoroutine(HidePanel(lastShowedPanel));
|
||||
StartCoroutine(ShowPanel(credits));
|
||||
anim.SetTrigger("rotate");
|
||||
}
|
||||
|
||||
public void OnExitClick()
|
||||
{
|
||||
confirmationQuestionLeft.text = "¿Estás seguro de que deseas salir?";
|
||||
confirmTrigger = "EXIT";
|
||||
|
||||
StartCoroutine(HidePanel(lastShowedPanel));
|
||||
StartCoroutine(ShowPanel(confirmationLeft));
|
||||
anim.SetTrigger("rotate");
|
||||
}
|
||||
|
||||
public void OnExitClickDirectly()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
public void OnExitMenuClick()
|
||||
{
|
||||
confirmationQuestionLeft.text = "¿Estás seguro de que deseas reiniciar el juego?\r\nTodo el progreso se perderá.";
|
||||
confirmTrigger = "RESTART";
|
||||
StartCoroutine(AudioManager.instance.FadeOut("01_jardin", 1));
|
||||
StartCoroutine(HidePanel(lastShowedPanel));
|
||||
StartCoroutine(ShowPanel(confirmationLeft));
|
||||
anim.SetTrigger("rotate");
|
||||
}
|
||||
public void OnExitMenuClickDirectly()
|
||||
{
|
||||
AudioManager.instance.StopAll();
|
||||
BetweenScenePass.instance.GameRestarted = true;
|
||||
BetweenScenePass.instance.RestartData();
|
||||
sceneTransition.CloseScene("Scenes/Menu");
|
||||
}
|
||||
|
||||
public void OnBacktMenuClick()
|
||||
{
|
||||
confirmationQuestionLeft.text = "¿Estás seguro de que deseas volver al jardín?";
|
||||
confirmTrigger = "BACK_MENU";
|
||||
|
||||
StartCoroutine(HidePanel(lastShowedPanel));
|
||||
StartCoroutine(ShowPanel(confirmationLeft));
|
||||
anim.SetTrigger("rotate");
|
||||
}
|
||||
|
||||
public void OnBackClick()
|
||||
{
|
||||
StartCoroutine(HidePanel(lastShowedPanel));
|
||||
|
||||
if (mainMenuOnBackClick)
|
||||
{
|
||||
StartCoroutine(ShowPanel(mainMenu));
|
||||
}
|
||||
else
|
||||
{
|
||||
StartCoroutine(ShowPanel(pauseMenu));
|
||||
}
|
||||
|
||||
anim.SetTrigger("rotate");
|
||||
}
|
||||
|
||||
public void OnConfirmAccept()
|
||||
{
|
||||
switch (confirmTrigger)
|
||||
{
|
||||
case "EXIT":
|
||||
Application.Quit();
|
||||
break;
|
||||
case "RESTART":
|
||||
Time.timeScale = 1;
|
||||
BetweenScenePass.instance.GameRestarted = true;
|
||||
BetweenScenePass.instance.RestartData();
|
||||
AudioManager.instance.StopAll();
|
||||
sceneTransition.CloseScene("Scenes/Menu");
|
||||
break;
|
||||
case "BACK_MENU":
|
||||
Time.timeScale = 1;
|
||||
BetweenScenePass.instance.GameRestarted = false;
|
||||
AudioManager.instance.StopAll();
|
||||
sceneTransition.CloseScene("Scenes/Menu");
|
||||
break;
|
||||
case "SELECT_CHAR":
|
||||
characterSelectorController.GetComponent<CharSelSelectionController>().ConfirmPlay();
|
||||
anim.SetTrigger("pauseDown");
|
||||
Invoke("ReactivatePauseMenuAfterGoDown", 0.2f);
|
||||
break;
|
||||
}
|
||||
confirmTrigger = "";
|
||||
}
|
||||
|
||||
public void OnConfirmCancel()
|
||||
{
|
||||
switch (confirmTrigger)
|
||||
{
|
||||
case "SELECT_CHAR":
|
||||
nextCharButton.SetActive(true);
|
||||
prevCharButton.SetActive(true);
|
||||
playButton.SetActive(true);
|
||||
|
||||
anim.SetTrigger("pauseDown");
|
||||
Invoke("ReactivatePauseMenuAfterGoDown", 0.2f);
|
||||
break;
|
||||
default:
|
||||
OnBackClick();
|
||||
break;
|
||||
}
|
||||
|
||||
confirmTrigger = "";
|
||||
|
||||
}
|
||||
|
||||
public void OpensConfirmDirectly(string charName)
|
||||
{
|
||||
nextCharButton.SetActive(false);
|
||||
prevCharButton.SetActive(false);
|
||||
playButton.SetActive(false);
|
||||
|
||||
anim.SetTrigger("pauseUp");
|
||||
confirmationQuestionRight.text = "Quieres jugar con "+ charName + "? ";
|
||||
pauseMenu.SetActive(false);
|
||||
confirmationRight.SetActive(true);
|
||||
confirmTrigger = "SELECT_CHAR";
|
||||
}
|
||||
|
||||
|
||||
IEnumerator ShowPanel(GameObject panel)
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(showDelay);
|
||||
panel.SetActive(true);
|
||||
lastShowedPanel = panel;
|
||||
}
|
||||
|
||||
IEnumerator HidePanel(GameObject panel)
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(hideDelay);
|
||||
panel.SetActive(false);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f9dd5688318195d4ab12a95ba6d3fd98
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
102
Assets/Scripts/CharacterSelection/MainMenuDelay.cs
Normal file
102
Assets/Scripts/CharacterSelection/MainMenuDelay.cs
Normal file
|
@ -0,0 +1,102 @@
|
|||
using Cinemachine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class MainMenuDelay : MonoBehaviour{
|
||||
|
||||
[SerializeField] float delay;
|
||||
[SerializeField] GameObject invitation;
|
||||
|
||||
[SerializeField] CMCameraRail cinematic;
|
||||
[SerializeField] GameObject cam;
|
||||
[SerializeField] GameObject mainCam;
|
||||
[SerializeField] GameObject track;
|
||||
[SerializeField] GameObject player;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
StartCoroutine(StartCameraController());
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
}
|
||||
|
||||
IEnumerator StartCameraController()
|
||||
{
|
||||
|
||||
Cursor.visible = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
|
||||
yield return new WaitUntil(() => BetweenScenePass.instance != null);
|
||||
|
||||
if (BetweenScenePass.instance && BetweenScenePass.instance.GameRestarted)
|
||||
{
|
||||
AudioManager.instance.Play("transicion", 0f);
|
||||
AudioManager.instance.Play("SFX_vocesBackground");
|
||||
|
||||
cam.SetActive(true);
|
||||
track.SetActive(true);
|
||||
|
||||
player.SetActive(false);
|
||||
cinematic.StartRail();
|
||||
StartCoroutine(ActivateMenu(false));
|
||||
}
|
||||
else
|
||||
{
|
||||
AudioManager.instance.Play("01_jardin", 0f);
|
||||
|
||||
player.transform.position = new Vector3(0f, 1.08f, -7.68f);
|
||||
|
||||
track.SetActive(false);
|
||||
|
||||
player.SetActive(true);
|
||||
|
||||
cam.SetActive(false);
|
||||
mainCam.SetActive(true);
|
||||
mainCam.GetComponent<CinemachineFreeLook>().m_YAxis.Value = 0.5f;
|
||||
mainCam.GetComponent<CinemachineFreeLook>().m_XAxis.Value = -180;
|
||||
|
||||
GameObject selectedNPC;
|
||||
if (BetweenScenePass.instance.PlayerCharacterId >= 0)
|
||||
{
|
||||
selectedNPC = GameObject.Find("LevelNPC_" + BetweenScenePass.instance.PlayerCharacterId);
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedNPC = GameObject.Find("LevelNPC_0");
|
||||
}
|
||||
|
||||
player.GetComponent<MenuPlayerMovement>().anim = player.GetComponent<CharacterIdController>().SetPlayerCustom();
|
||||
player.GetComponent<MenuPlayerMovement>().anim.SetFloat("Dance", Random.Range(1f, 6f));
|
||||
|
||||
//player.transform.position = new Vector3(selectedNPC.transform.position.x, 1.08f, selectedNPC.transform.position.z);
|
||||
//player.transform.rotation = selectedNPC.transform.rotation;
|
||||
|
||||
selectedNPC.SetActive(false);
|
||||
|
||||
delay = 0;
|
||||
StartCoroutine(ActivateMenu(true));
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator ActivateMenu(bool lockMouse){
|
||||
yield return new WaitForSecondsRealtime(delay);
|
||||
StartCoroutine(AudioManager.instance.FadeOut("transicion", 1));
|
||||
StartCoroutine(AudioManager.instance.FadeIn("01_jardin", 1));
|
||||
invitation.GetComponent<Animator>().SetTrigger("startMainMenu");
|
||||
|
||||
if (lockMouse)
|
||||
{
|
||||
Cursor.visible = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
else
|
||||
{
|
||||
Cursor.visible = true;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/CharacterSelection/MainMenuDelay.cs.meta
Normal file
11
Assets/Scripts/CharacterSelection/MainMenuDelay.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f98f96de459bb134a92c1f749c98b7ef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
14
Assets/Scripts/CursorController.cs
Normal file
14
Assets/Scripts/CursorController.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CursorController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] Texture2D cursor;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Cursor.SetCursor(cursor, Vector2.zero, CursorMode.ForceSoftware);
|
||||
}
|
||||
}
|
11
Assets/Scripts/CursorController.cs.meta
Normal file
11
Assets/Scripts/CursorController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 06597796646874d4995c23fea9d94994
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
55
Assets/Scripts/EndGameController.cs
Normal file
55
Assets/Scripts/EndGameController.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class EndGameController : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] CMCameraRail rail;
|
||||
|
||||
[SerializeField] CanvasGroup credits;
|
||||
|
||||
bool creditsAlpha = false;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
rail.StartRail();
|
||||
StartCoroutine(AudioManager.instance.FadeIn("final_minijuego", 1));
|
||||
StartCoroutine(PlayKidsSound(3, 6));
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (creditsAlpha)
|
||||
{
|
||||
credits.alpha += Time.deltaTime;
|
||||
|
||||
if(credits.alpha >= 1)
|
||||
{
|
||||
creditsAlpha = false;
|
||||
Cursor.visible = true;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowCredits()
|
||||
{
|
||||
creditsAlpha = true;
|
||||
}
|
||||
|
||||
private IEnumerator PlayKidsSound(float maxDelay, float minDelay)
|
||||
{
|
||||
float i = 0;
|
||||
float delay = 0;
|
||||
while (i < 100000)
|
||||
{
|
||||
delay = Random.Range(minDelay, maxDelay);
|
||||
i += Time.deltaTime;
|
||||
AudioManager.instance.PlayOneShot("SFX_cheering");
|
||||
yield return new WaitForSecondsRealtime(delay);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/EndGameController.cs.meta
Normal file
11
Assets/Scripts/EndGameController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a5e1630dfabb6d0449a6c157caf629d3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
122
Assets/Scripts/EndGameScoreCounter.cs
Normal file
122
Assets/Scripts/EndGameScoreCounter.cs
Normal file
|
@ -0,0 +1,122 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class EndGameScoreCounter : MonoBehaviour
|
||||
{
|
||||
SortedDictionary<int, int> scoreByChar;
|
||||
|
||||
[SerializeField] GameObject winnerChar;
|
||||
[SerializeField] List<GameObject> secondWinnerChar;
|
||||
[SerializeField] List<GameObject> looserChars;
|
||||
|
||||
BetweenScenePass data;
|
||||
|
||||
|
||||
void Awake()
|
||||
{
|
||||
scoreByChar = new SortedDictionary<int, int>();
|
||||
scoreByChar[0] = 0;
|
||||
scoreByChar[1] = 0;
|
||||
scoreByChar[2] = 0;
|
||||
scoreByChar[3] = 0;
|
||||
scoreByChar[4] = 0;
|
||||
scoreByChar[5] = 0;
|
||||
|
||||
StartCoroutine(CountScore());
|
||||
}
|
||||
|
||||
IEnumerator CountScore()
|
||||
{
|
||||
data = BetweenScenePass.instance;
|
||||
|
||||
yield return new WaitUntil(() => data != null);
|
||||
|
||||
DistributeScoreByCharacter();
|
||||
}
|
||||
|
||||
void DistributeScoreByCharacter()
|
||||
{
|
||||
Debug.Log("cha");
|
||||
|
||||
for (int i = 0; i < data.CharacterScore[BetweenScenePass.Games.Swords].Count; i++)
|
||||
{
|
||||
scoreByChar[i] += data.CharacterScore[BetweenScenePass.Games.Swords][i];
|
||||
}
|
||||
for (int i = 0; i < data.CharacterScore[BetweenScenePass.Games.Sacks].Count; i++)
|
||||
{
|
||||
scoreByChar[i] += data.CharacterScore[BetweenScenePass.Games.Sacks][i];
|
||||
}
|
||||
for (int i = 0; i < data.CharacterScore[BetweenScenePass.Games.Chairs].Count; i++)
|
||||
{
|
||||
scoreByChar[i] += data.CharacterScore[BetweenScenePass.Games.Chairs][i];
|
||||
}
|
||||
for (int i = 0; i < data.CharacterScore[BetweenScenePass.Games.Jousting].Count; i++)
|
||||
{
|
||||
scoreByChar[i] += data.CharacterScore[BetweenScenePass.Games.Jousting][i];
|
||||
}
|
||||
for (int i = 0; i < data.CharacterScore[BetweenScenePass.Games.Baloons].Count; i++)
|
||||
{
|
||||
scoreByChar[i] += data.CharacterScore[BetweenScenePass.Games.Baloons][i];
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
Debug.Log("char: " + i + " - score: " + scoreByChar[i]);
|
||||
}
|
||||
|
||||
int winner = GetWinner(-1);
|
||||
|
||||
scoreByChar.Remove(winner);
|
||||
int winner2 = GetWinner(winner);
|
||||
|
||||
scoreByChar.Remove(winner2);
|
||||
int winner3 = GetWinner(winner2);
|
||||
|
||||
scoreByChar.Remove(winner3);
|
||||
|
||||
|
||||
winnerChar.GetComponent<CharacterIdController>().SetNpcCustom(winner);
|
||||
winnerChar.GetComponent<CharacterIdController>().DanceDance(winner + 1);
|
||||
|
||||
secondWinnerChar[0].GetComponent<CharacterIdController>().SetNpcCustom(winner2);
|
||||
secondWinnerChar[0].GetComponent<CharacterIdController>().DanceDance(winner2 + 1);
|
||||
|
||||
secondWinnerChar[1].GetComponent<CharacterIdController>().SetNpcCustom(winner3);
|
||||
secondWinnerChar[1].GetComponent<CharacterIdController>().DanceDance(winner3 + 1);
|
||||
|
||||
int looserIndex = 0;
|
||||
foreach (KeyValuePair<int, int> entry in scoreByChar)
|
||||
{
|
||||
looserChars[looserIndex].GetComponent<CharacterIdController>().SetNpcCustom(entry.Key);
|
||||
looserChars[looserIndex].GetComponent<CharacterIdController>().DanceDance(entry.Key + 1);
|
||||
looserIndex++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int GetWinner(int lastWinner)
|
||||
{
|
||||
int maxScore = 0;
|
||||
int winner = 0;
|
||||
|
||||
foreach (KeyValuePair<int, int> entry in scoreByChar)
|
||||
{
|
||||
if (entry.Value > maxScore && entry.Key != lastWinner)
|
||||
{
|
||||
maxScore = entry.Value;
|
||||
winner = entry.Key;
|
||||
}
|
||||
}
|
||||
|
||||
if (scoreByChar.ContainsKey(data.PlayerCharacterId) && scoreByChar[data.PlayerCharacterId] == maxScore)
|
||||
{
|
||||
return data.PlayerCharacterId;
|
||||
}
|
||||
|
||||
return winner;
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/EndGameScoreCounter.cs.meta
Normal file
11
Assets/Scripts/EndGameScoreCounter.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 170755591e4ea2a40ab1f6caf8c4ff2c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
20
Assets/Scripts/FollowPlayer.cs
Normal file
20
Assets/Scripts/FollowPlayer.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FollowPlayer : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] Transform jugador;
|
||||
|
||||
[SerializeField] Vector3 offset;
|
||||
|
||||
[SerializeField] float smooth = 0.125f;
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
transform.position = Vector3.Lerp(transform.position, jugador.position + offset, smooth);
|
||||
//transform.position = Vector3.SmoothDamp();
|
||||
}
|
||||
}
|
11
Assets/Scripts/FollowPlayer.cs.meta
Normal file
11
Assets/Scripts/FollowPlayer.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 75b0bf709bf57a64d8c0f5d2f4f26949
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
123
Assets/Scripts/GameTutorialControler.cs
Normal file
123
Assets/Scripts/GameTutorialControler.cs
Normal file
|
@ -0,0 +1,123 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.Video;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
[System.Serializable] public class TutorialClose : UnityEvent { }
|
||||
public class GameTutorialControler : MonoBehaviour
|
||||
{
|
||||
[Space(10)]
|
||||
[SerializeField] CMCameraRail cinematic;
|
||||
[SerializeField] GameObject initCinematic;
|
||||
[SerializeField] GameObject mainCamera;
|
||||
|
||||
[Space(10)]
|
||||
[SerializeField] GameObject cardboard;
|
||||
|
||||
[Space(10)]
|
||||
[SerializeField] string gameName;
|
||||
[SerializeField] TextMeshProUGUI gameNameText;
|
||||
|
||||
[Space(10)]
|
||||
[SerializeField] string gameDescription;
|
||||
[SerializeField] TextMeshProUGUI gameDescriptionText;
|
||||
|
||||
[Space(10)]
|
||||
[SerializeField] GameObject startButton;
|
||||
|
||||
[Space(10)]
|
||||
[SerializeField] GameObject controlsPanel;
|
||||
|
||||
[Space(10)]
|
||||
[SerializeField] GameObject videoPanel;
|
||||
[SerializeField] VideoClip video;
|
||||
|
||||
[Space(10)]
|
||||
[SerializeField] Animator anim;
|
||||
|
||||
|
||||
[Space]
|
||||
public TutorialClose onTutorialClose;
|
||||
|
||||
|
||||
CursorLockMode cursorLastState;
|
||||
|
||||
public bool gameStarted;
|
||||
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if(mainCamera != null)
|
||||
mainCamera.SetActive(false);
|
||||
|
||||
gameNameText.text = gameName;
|
||||
gameDescriptionText.text = gameDescription;
|
||||
|
||||
cinematic.StartRail();
|
||||
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
|
||||
gameStarted = false;
|
||||
|
||||
StartCoroutine(AudioManager.instance.FadeIn("transicion", 1));
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnStartClick()
|
||||
{
|
||||
Time.timeScale = 1;
|
||||
gameStarted = true;
|
||||
anim.SetTrigger("hide");
|
||||
|
||||
AudioManager.instance.PlayOneShot("SFX_click");
|
||||
|
||||
if (mainCamera != null)
|
||||
mainCamera.SetActive(true);
|
||||
|
||||
if (cursorLastState == CursorLockMode.Locked)
|
||||
{
|
||||
Cursor.visible = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
else
|
||||
{
|
||||
Cursor.visible = true;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
|
||||
if (onTutorialClose.GetPersistentEventCount() > 0)
|
||||
{
|
||||
onTutorialClose.Invoke();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void ShowTutorial()
|
||||
{
|
||||
anim.SetTrigger("show");
|
||||
initCinematic.SetActive(false);
|
||||
|
||||
cursorLastState = Cursor.lockState;
|
||||
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
|
||||
Time.timeScale = 0;
|
||||
}
|
||||
|
||||
public void UnlockCursor()
|
||||
{
|
||||
Cursor.visible = true;
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/GameTutorialControler.cs.meta
Normal file
11
Assets/Scripts/GameTutorialControler.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cfe2768b380cc1641afc4eff13377eee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Justa.meta
Normal file
8
Assets/Scripts/Justa.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e9c3d747e011e97448b0108c6b61178a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
193
Assets/Scripts/Justa/JustaGameController.cs
Normal file
193
Assets/Scripts/Justa/JustaGameController.cs
Normal file
|
@ -0,0 +1,193 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class JustaGameController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] ScenesTransitionController scenesTransition;
|
||||
[SerializeField] int actualRound = 1;
|
||||
|
||||
[SerializeField] JustaPlayerController player;
|
||||
[SerializeField] JustaPlayerController enemy;
|
||||
|
||||
[SerializeField] bool paused;
|
||||
|
||||
[SerializeField] GameObject countDownPanel;
|
||||
|
||||
[SerializeField] JustaTargetComboObjects[] targetObjects;
|
||||
|
||||
[SerializeField] Image player_HPBar;
|
||||
[SerializeField] Image enemy_HPBar;
|
||||
|
||||
[SerializeField] JustaTrigger trigger;
|
||||
|
||||
[SerializeField] GameObject gameHUD;
|
||||
|
||||
bool scoreDistributed;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
//BeforeGame();
|
||||
StartCoroutine(AudioManager.instance.FadeIn("transicion", 1));
|
||||
}
|
||||
|
||||
private void BeforeGame()
|
||||
{
|
||||
StartCoroutine(BeforeGameCoroutine());
|
||||
}
|
||||
|
||||
private IEnumerator BeforeGameCoroutine()
|
||||
{
|
||||
|
||||
//Cinematica inicial
|
||||
yield return new WaitForSecondsRealtime(2);
|
||||
//Tutorial
|
||||
StartGame();
|
||||
}
|
||||
|
||||
public void StartGame()
|
||||
{
|
||||
StartCoroutine(AudioManager.instance.FadeOut("transicion", 1));
|
||||
StartCoroutine(AudioManager.instance.FadeIn("02_caballos", 1));
|
||||
StartCoroutine(StartGameCoroutine());
|
||||
}
|
||||
|
||||
private IEnumerator StartGameCoroutine()
|
||||
{
|
||||
ShowGameHUD();
|
||||
while (!GameFinished())
|
||||
{
|
||||
Debug.Log("Ronda: " + actualRound);
|
||||
Debug.Log("Vida enemy " + enemy.GetCurrentLives() + " vida player " + player.GetCurrentLives());
|
||||
SetNewCombo();
|
||||
countDownPanel.SetActive(true);
|
||||
yield return new WaitForSecondsRealtime(4f);
|
||||
AudioManager.instance.PlayOneShot("SFX_silbato");
|
||||
countDownPanel.SetActive(false);
|
||||
trigger.paused = false;
|
||||
enemy.StartRunning();
|
||||
player.StartRunning();
|
||||
yield return new WaitForSecondsRealtime(9f);
|
||||
trigger.paused = true;
|
||||
CreateEnemyPuntuation();
|
||||
CheckRoundWinner();
|
||||
actualRound++;
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
|
||||
private void CreateEnemyPuntuation()
|
||||
{
|
||||
float points = Random.Range(1f, 5f);
|
||||
enemy.SetRoundPoints(points);
|
||||
}
|
||||
|
||||
private bool GameFinished()
|
||||
{
|
||||
if (player.GetCurrentLives() <= 0)
|
||||
{
|
||||
ReturnToMenu(enemy.GetComponent<CharacterIdController>().characterId, player.GetComponent<CharacterIdController>().characterId);
|
||||
return true;
|
||||
}
|
||||
if (enemy.GetCurrentLives() <= 0)
|
||||
{
|
||||
ReturnToMenu(player.GetComponent<CharacterIdController>().characterId, enemy.GetComponent<CharacterIdController>().characterId);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void CheckRoundWinner()
|
||||
{
|
||||
float enemyPoints = enemy.GetRoundPoints();
|
||||
float playerPoints = player.GetRoundPoints();
|
||||
if (enemyPoints <= playerPoints)
|
||||
{
|
||||
Debug.Log("Has ganado la ronda: enemigo: " + enemyPoints + " tuyos:" + playerPoints);
|
||||
AudioManager.instance.PlayOneShot("SFX_campanillas");
|
||||
enemy_HPBar.fillAmount -= 0.2f;
|
||||
LooseLife(enemy);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Has ganado la ronda: enemigo: " + enemyPoints + " tuyos:" + playerPoints);
|
||||
player_HPBar.fillAmount -= 0.2f;
|
||||
LooseLife(player);
|
||||
}
|
||||
enemy.SetRoundPoints(0);
|
||||
player.SetRoundPoints(0);
|
||||
}
|
||||
|
||||
private void LooseLife(JustaPlayerController character)
|
||||
{
|
||||
character.LooseLife();
|
||||
}
|
||||
|
||||
private void SetNewCombo()
|
||||
{
|
||||
foreach (JustaTargetComboObjects target in targetObjects)
|
||||
{
|
||||
target.SetRandomKey();
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ShowGameHUD()
|
||||
{
|
||||
gameHUD.SetActive(true);
|
||||
}
|
||||
|
||||
void ReturnToMenu(int winner, int looser) {
|
||||
StartCoroutine(AudioManager.instance.FadeOut("02_caballos", 1));
|
||||
if (!scoreDistributed)
|
||||
{
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Jousting,
|
||||
winner,
|
||||
null));
|
||||
|
||||
int newWinner1 = winner;
|
||||
int i = 0;
|
||||
while (i <100)
|
||||
{
|
||||
newWinner1 = Random.Range(0, 6);
|
||||
i++;
|
||||
if (newWinner1 != winner && newWinner1 != looser)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Jousting,
|
||||
newWinner1,
|
||||
null));
|
||||
|
||||
int newWinner2;
|
||||
newWinner2 = winner;
|
||||
i = 0;
|
||||
while (i <100)
|
||||
{
|
||||
newWinner2 = Random.Range(0, 6);
|
||||
i++;
|
||||
if (newWinner2 != winner && newWinner2 != looser && newWinner2 != newWinner1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Jousting,
|
||||
newWinner2,
|
||||
scenesTransition));
|
||||
scoreDistributed = true;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Justa/JustaGameController.cs.meta
Normal file
11
Assets/Scripts/Justa/JustaGameController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3baa8fd2b3cfaa048884ebc2be0a07d9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
164
Assets/Scripts/Justa/JustaPlayerController.cs
Normal file
164
Assets/Scripts/Justa/JustaPlayerController.cs
Normal file
|
@ -0,0 +1,164 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class JustaPlayerController : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] float speed;
|
||||
[SerializeField] float maxSpeed;
|
||||
[SerializeField] float aceleration;
|
||||
[SerializeField] float timeOfRunning;
|
||||
[SerializeField] float timeOfBracking;
|
||||
|
||||
[SerializeField] float timeBetweenRounds;
|
||||
|
||||
[SerializeField] public Animator anim;
|
||||
|
||||
Vector3 initialPos;
|
||||
|
||||
[SerializeField] int maxLives;
|
||||
int currentLife;
|
||||
|
||||
[SerializeField] float roundPoints = 0;
|
||||
|
||||
[SerializeField] JustaTrigger trigger;
|
||||
[SerializeField] float multiplier;
|
||||
[SerializeField] float mistakePoints;
|
||||
|
||||
[SerializeField] GameObject feedbackError;
|
||||
[SerializeField] GameObject feedbackGreat;
|
||||
[SerializeField] GameObject feedbackPerfect;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
if (CompareTag("Player"))
|
||||
anim = GetComponent<CharacterIdController>().SetPlayerCustom();
|
||||
|
||||
initialPos = this.transform.position;
|
||||
currentLife = maxLives;
|
||||
//StartRunning();
|
||||
}
|
||||
|
||||
public int GetCurrentLives()
|
||||
{
|
||||
return this.currentLife;
|
||||
}
|
||||
|
||||
public float GetRoundPoints()
|
||||
{
|
||||
return this.roundPoints;
|
||||
}
|
||||
|
||||
public void SetRoundPoints(float points)
|
||||
{
|
||||
this.roundPoints = points;
|
||||
}
|
||||
|
||||
public void Mistake()
|
||||
{
|
||||
//Mal activar
|
||||
StartCoroutine(ActivateFeedBack(feedbackError));
|
||||
roundPoints -= mistakePoints;
|
||||
if (roundPoints < 0)
|
||||
{
|
||||
roundPoints = 0;
|
||||
}
|
||||
//Debug.Log("Fallo. Puntos actual: " + roundPoints);
|
||||
}
|
||||
|
||||
public void WinPoints(float distance)
|
||||
{
|
||||
//Max distance = 0.5 -> 0,5 puntos
|
||||
//Min distance = 0 -> 2 puntos
|
||||
float points = 0;
|
||||
if (distance <= 0.2f)
|
||||
{
|
||||
points = 2;
|
||||
//Genial activar
|
||||
StartCoroutine(ActivateFeedBack(feedbackPerfect));
|
||||
} else if (distance > 0.2f && distance < 0.5f)
|
||||
{
|
||||
points = 1;
|
||||
//Bien activar
|
||||
StartCoroutine(ActivateFeedBack(feedbackGreat));
|
||||
}
|
||||
else
|
||||
{
|
||||
points = 0.5f;
|
||||
//Bien activar
|
||||
StartCoroutine(ActivateFeedBack(feedbackGreat));
|
||||
}
|
||||
roundPoints += points;
|
||||
//Debug.Log("Puntos ganados: " + points + " puntos totales: " + roundPoints);
|
||||
}
|
||||
|
||||
private IEnumerator ActivateFeedBack(GameObject feedback)
|
||||
{
|
||||
feedback.SetActive(true);
|
||||
yield return new WaitForSeconds(0.3f);
|
||||
feedback.SetActive(false);
|
||||
}
|
||||
|
||||
public void LooseLife()
|
||||
{
|
||||
currentLife--;
|
||||
}
|
||||
|
||||
public void StartRunning()
|
||||
{
|
||||
StartCoroutine(StartRunningCoroutine());
|
||||
}
|
||||
|
||||
private IEnumerator PasosCaballo(float delay)
|
||||
{
|
||||
float i = 0;
|
||||
while (true && i < 10000)
|
||||
{
|
||||
i += 0.1f;
|
||||
AudioManager.instance.PlayOneShot("SFX_pasosCaballo"+Random.Range(1,5), true);
|
||||
yield return new WaitForSecondsRealtime(delay);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator StartRunningCoroutine()
|
||||
{
|
||||
float i = 0;
|
||||
Coroutine corutina = StartCoroutine(PasosCaballo(0.45f));
|
||||
while (i < timeOfRunning)
|
||||
{
|
||||
i += Time.deltaTime;
|
||||
if (speed < maxSpeed)
|
||||
{
|
||||
speed += Time.deltaTime * aceleration;
|
||||
}
|
||||
anim.SetFloat("VelocityY", speed);
|
||||
this.transform.Translate(Vector3.forward * speed * Time.deltaTime);
|
||||
yield return null;
|
||||
}
|
||||
StopCoroutine(corutina);
|
||||
corutina = StartCoroutine(PasosCaballo(0.65f));
|
||||
i = 0;
|
||||
while (i < timeOfBracking)
|
||||
{
|
||||
i += Time.deltaTime;
|
||||
if (speed > 0)
|
||||
{
|
||||
speed -= Time.deltaTime * aceleration * 2;
|
||||
}
|
||||
anim.SetFloat("VelocityY", speed);
|
||||
this.transform.Translate(Vector3.forward * speed * Time.deltaTime);
|
||||
yield return null;
|
||||
}
|
||||
StopCoroutine(corutina);
|
||||
yield return new WaitForSecondsRealtime(timeBetweenRounds);
|
||||
ResetPlayer();
|
||||
}
|
||||
|
||||
private void ResetPlayer()
|
||||
{
|
||||
this.transform.position = initialPos;
|
||||
this.roundPoints = 0;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Justa/JustaPlayerController.cs.meta
Normal file
11
Assets/Scripts/Justa/JustaPlayerController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8649b0a7466d9e64ab78e7f7f44d4e6a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
43
Assets/Scripts/Justa/JustaTargetComboObjects.cs
Normal file
43
Assets/Scripts/Justa/JustaTargetComboObjects.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
public class JustaTargetComboObjects : MonoBehaviour
|
||||
{
|
||||
public enum KeyType { W, A, S, D};
|
||||
|
||||
public KeyType key;
|
||||
|
||||
[SerializeField] TextMeshPro text;
|
||||
|
||||
public void SetRandomKey()
|
||||
{
|
||||
int num = UnityEngine.Random.Range(0, Enum.GetValues(typeof(KeyType)).Length);
|
||||
switch (num)
|
||||
{
|
||||
case 0:
|
||||
key = KeyType.W;
|
||||
text.text = "W";
|
||||
break;
|
||||
case 1:
|
||||
key = KeyType.A;
|
||||
text.text = "A";
|
||||
break;
|
||||
case 2:
|
||||
key = KeyType.S;
|
||||
text.text = "S";
|
||||
break;
|
||||
case 3:
|
||||
key = KeyType.D;
|
||||
text.text = "D";
|
||||
break;
|
||||
default:
|
||||
key = KeyType.W;
|
||||
text.text = "W";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/Justa/JustaTargetComboObjects.cs.meta
Normal file
11
Assets/Scripts/Justa/JustaTargetComboObjects.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8de51315d03e58d438548df4f244dd56
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
115
Assets/Scripts/Justa/JustaTrigger.cs
Normal file
115
Assets/Scripts/Justa/JustaTrigger.cs
Normal file
|
@ -0,0 +1,115 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class JustaTrigger : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] JustaPlayerController player;
|
||||
|
||||
JustaTargetComboObjects targetCollisioning = null;
|
||||
|
||||
[HideInInspector] public bool paused = true;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (!paused)
|
||||
{
|
||||
if (Input.anyKeyDown)
|
||||
{
|
||||
if (!Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
AudioManager.instance.PlayOneShot("SFX_caballoBufido" + UnityEngine.Random.Range(1, 3), true);
|
||||
|
||||
if (targetCollisioning == null)
|
||||
{
|
||||
LoosePoints();
|
||||
}
|
||||
else
|
||||
{
|
||||
JustaTargetComboObjects.KeyType key = targetCollisioning.key;
|
||||
switch (key)
|
||||
{
|
||||
case JustaTargetComboObjects.KeyType.W:
|
||||
if (Input.GetKeyDown(KeyCode.W))
|
||||
{
|
||||
WinPoints(this.transform.position, targetCollisioning.gameObject.transform.position);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoosePoints();
|
||||
}
|
||||
break;
|
||||
case JustaTargetComboObjects.KeyType.A:
|
||||
if (Input.GetKeyDown(KeyCode.A))
|
||||
{
|
||||
WinPoints(this.transform.position, targetCollisioning.gameObject.transform.position);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoosePoints();
|
||||
}
|
||||
break;
|
||||
case JustaTargetComboObjects.KeyType.S:
|
||||
if (Input.GetKeyDown(KeyCode.S))
|
||||
{
|
||||
WinPoints(this.transform.position, targetCollisioning.gameObject.transform.position);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoosePoints();
|
||||
}
|
||||
break;
|
||||
case JustaTargetComboObjects.KeyType.D:
|
||||
if (Input.GetKeyDown(KeyCode.D))
|
||||
{
|
||||
WinPoints(this.transform.position, targetCollisioning.gameObject.transform.position);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoosePoints();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void LoosePoints()
|
||||
{
|
||||
player.Mistake();
|
||||
}
|
||||
|
||||
private void WinPoints(Vector3 triggerPos, Vector3 targetPos)
|
||||
{
|
||||
float distance = Vector3.Distance(triggerPos, targetPos);
|
||||
player.WinPoints(distance);
|
||||
}
|
||||
|
||||
private void OnTriggerStay(Collider other)
|
||||
{
|
||||
if (other.CompareTag("TargetJusta"))
|
||||
{
|
||||
if (targetCollisioning == null)
|
||||
{
|
||||
targetCollisioning = other.GetComponent<JustaTargetComboObjects>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (other.CompareTag("TargetJusta"))
|
||||
{
|
||||
if (targetCollisioning != null)
|
||||
{
|
||||
targetCollisioning = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Justa/JustaTrigger.cs.meta
Normal file
11
Assets/Scripts/Justa/JustaTrigger.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ddecee5adb1505e4f8680dbe65264595
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
79
Assets/Scripts/LightRingController.cs
Normal file
79
Assets/Scripts/LightRingController.cs
Normal file
|
@ -0,0 +1,79 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class LightRingController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] Animator textAnim;
|
||||
[SerializeField] ScenesTransitionController scenesTransition;
|
||||
[SerializeField] GameObject ringParent;
|
||||
[SerializeField] Animator anim;
|
||||
[SerializeField] BetweenScenePass.Games game;
|
||||
|
||||
[SerializeField] bool isOnRange;
|
||||
|
||||
BetweenScenePass gameData;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if(gameData == null)
|
||||
gameData = BetweenScenePass.instance;
|
||||
|
||||
ringParent.SetActive(!gameData.GamesPlayed[game]);
|
||||
}
|
||||
|
||||
void HideRing()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if(isOnRange && Input.GetMouseButtonDown(0) && Time.timeScale == 1)
|
||||
{
|
||||
anim.SetTrigger("start");
|
||||
|
||||
StartCoroutine(AudioManager.instance.FadeOut("01_jardin", 1));
|
||||
StartCoroutine(AudioManager.instance.FadeOut("SFX_aura", .5f));
|
||||
scenesTransition.CloseScene(gameData.GamesScenes[game]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
StartCoroutine(AudioManager.instance.FadeIn("SFX_aura", .5f));
|
||||
isOnRange = true;
|
||||
anim.SetTrigger("up");
|
||||
|
||||
textAnim.gameObject.SetActive(true);
|
||||
//textAnim.SetTrigger("textUp");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
StartCoroutine(AudioManager.instance.FadeOut("SFX_aura", .5f));
|
||||
StartCoroutine(AudioManager.instance.FadeIn("SFX_vocesBackground", .5f));
|
||||
isOnRange = false;
|
||||
anim.SetTrigger("down");
|
||||
|
||||
textAnim.SetTrigger("textDown");
|
||||
StartCoroutine(HideText());
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator HideText()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.21f);
|
||||
textAnim.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
|
||||
}
|
11
Assets/Scripts/LightRingController.cs.meta
Normal file
11
Assets/Scripts/LightRingController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 21ef64585d5ca7944a4c0edf069400f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Menu.meta
Normal file
8
Assets/Scripts/Menu.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 85e502ce81ea3f84596bad64de30a547
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
89
Assets/Scripts/Menu/MenuPlayerMovement.cs
Normal file
89
Assets/Scripts/Menu/MenuPlayerMovement.cs
Normal file
|
@ -0,0 +1,89 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MenuPlayerMovement : MonoBehaviour{
|
||||
|
||||
[SerializeField] Transform cam;
|
||||
[SerializeField] float speed = 7.5f;
|
||||
CharacterController controller;
|
||||
[SerializeField] public Animator anim;
|
||||
|
||||
[SerializeField] float gravityScale = 9.8f;
|
||||
[SerializeField] LayerMask whatIsGround = -1;
|
||||
[SerializeField] float feetRadius;
|
||||
[SerializeField] Transform feetPos;
|
||||
bool isGrounded;
|
||||
Vector3 velocity;
|
||||
|
||||
float yVelocity;
|
||||
float yVelocityVelocity;
|
||||
|
||||
[SerializeField, Range(0, .3f)] float turnSmoothTime = .1f;
|
||||
float turnSmoothVelocity;
|
||||
|
||||
|
||||
[SerializeField, Min(0)] float gravity = 15f;
|
||||
|
||||
float currentX;
|
||||
float xDirVelocity;
|
||||
float currentY;
|
||||
float yDirVelocity;
|
||||
float velocityChangeVelocity;
|
||||
|
||||
[SerializeField, Range(0, 1f)] float stepsInterval = .5f;
|
||||
float currentTime;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
controller = GetComponent<CharacterController>();
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Cursor.visible = false;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (anim != null && Time.timeScale == 1)
|
||||
{
|
||||
|
||||
float horizontal = Input.GetAxisRaw("Horizontal");
|
||||
float vertical = Input.GetAxisRaw("Vertical");
|
||||
Vector3 direction = new Vector3(horizontal, 0, vertical).normalized;
|
||||
|
||||
if (direction.magnitude >= .1f)
|
||||
{
|
||||
currentTime += Time.deltaTime;
|
||||
if(currentTime >= stepsInterval){
|
||||
AudioManager.instance.PlayOneShot("SFX_paso" + Random.Range(1, 6), true);
|
||||
currentTime = 0;
|
||||
}
|
||||
|
||||
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
|
||||
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
|
||||
transform.rotation = Quaternion.Euler(0, angle, 0);
|
||||
|
||||
Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
|
||||
controller.Move(moveDir.normalized * speed * Time.deltaTime);
|
||||
|
||||
Vector3 directionX = direction.x * transform.forward;
|
||||
Vector3 directionZ = direction.z * transform.forward;
|
||||
currentX = Mathf.SmoothDamp(currentX, directionX.x, ref xDirVelocity, .1f);
|
||||
currentY = Mathf.SmoothDamp(currentY, directionZ.z, ref xDirVelocity, .1f);
|
||||
anim.SetFloat("Dance", 0);
|
||||
yDirVelocity = 1;
|
||||
}else{
|
||||
currentX = Mathf.SmoothDamp(currentX, 0, ref xDirVelocity, .1f);
|
||||
currentY = Mathf.SmoothDamp(currentY, 0, ref xDirVelocity, .1f);
|
||||
yDirVelocity = 0;
|
||||
}
|
||||
|
||||
float vel = Mathf.SmoothDamp(anim.GetFloat("VelocityY"), yDirVelocity, ref velocityChangeVelocity, .1f);
|
||||
anim.SetFloat("VelocityY", vel);
|
||||
|
||||
velocity.y -= gravity * Time.deltaTime;
|
||||
controller.Move(velocity * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/Menu/MenuPlayerMovement.cs.meta
Normal file
11
Assets/Scripts/Menu/MenuPlayerMovement.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fcc3d572367c55141bb86a759b2d2a77
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
26
Assets/Scripts/Menu/PlaySounds.cs
Normal file
26
Assets/Scripts/Menu/PlaySounds.cs
Normal file
|
@ -0,0 +1,26 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlaySounds : MonoBehaviour{
|
||||
|
||||
[SerializeField] bool playIntro = true;
|
||||
|
||||
void Start(){
|
||||
if (playIntro){
|
||||
AudioManager.instance.Play("Intro");
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayMusic(string name){
|
||||
AudioManager.instance.Play(name);
|
||||
}
|
||||
|
||||
public void StopMusic(string name){
|
||||
AudioManager.instance.Play(name);
|
||||
}
|
||||
|
||||
public void PlayOneShot(string name){
|
||||
AudioManager.instance.PlayOneShot(name);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Menu/PlaySounds.cs.meta
Normal file
11
Assets/Scripts/Menu/PlaySounds.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b8aafc487c65f41488d855dbfa6e5ed7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
69
Assets/Scripts/NPCSkinController.cs
Normal file
69
Assets/Scripts/NPCSkinController.cs
Normal file
|
@ -0,0 +1,69 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class NPCSkinController : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] List<CharacterIdController> npcs;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
BetweenScenePass data = BetweenScenePass.instance;
|
||||
int npcCount = npcs.Count;
|
||||
|
||||
if (data && data.NpcCharacterId.Count > 0) {
|
||||
|
||||
data.NpcCharacterId.Sort((a, b) => 1 - 2 * Random.Range(0, 1));
|
||||
|
||||
for (int i = 0; i < data.NpcCharacterId.Count; i++)
|
||||
{
|
||||
Animator modelAnim = npcs[i].ActivateModel(data.NpcCharacterId[i]);
|
||||
|
||||
if (SceneManager.GetActiveScene().name == "Sillas")
|
||||
npcs[i].gameObject.GetComponent<ChairsEnemyController>().anim = modelAnim;
|
||||
|
||||
if (SceneManager.GetActiveScene().name == "CarreraSacos")
|
||||
npcs[i].gameObject.GetComponent<SaltosSacosController>().anim = modelAnim;
|
||||
|
||||
if (SceneManager.GetActiveScene().name == "Justa")
|
||||
{
|
||||
if(npcs[i].gameObject.GetComponent<JustaPlayerController>())
|
||||
npcs[i].gameObject.GetComponent<JustaPlayerController>().anim = modelAnim;
|
||||
|
||||
if (!npcs[i].gameObject.CompareTag("Enemy"))
|
||||
npcs[i].DanceDance(Random.Range(0, 5));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < npcCount; i++)
|
||||
{
|
||||
Animator modelAnim = npcs[i].ActivateModel(i);
|
||||
|
||||
if (SceneManager.GetActiveScene().name == "Sillas")
|
||||
npcs[i].gameObject.GetComponent<ChairsEnemyController>().anim = modelAnim;
|
||||
|
||||
if (SceneManager.GetActiveScene().name == "CarreraSacos")
|
||||
npcs[i].gameObject.GetComponent<SaltosSacosController>().anim = modelAnim;
|
||||
|
||||
if (SceneManager.GetActiveScene().name == "Justa")
|
||||
{
|
||||
if(npcs[i].gameObject.GetComponent<JustaPlayerController>())
|
||||
npcs[i].gameObject.GetComponent<JustaPlayerController>().anim = modelAnim;
|
||||
|
||||
if (!npcs[i].gameObject.CompareTag("Enemy"))
|
||||
npcs[i].DanceDance(Random.Range(0, 5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/NPCSkinController.cs.meta
Normal file
11
Assets/Scripts/NPCSkinController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: de527fede79cf574d9d991a3d4815e8a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
92
Assets/Scripts/PauseMenu.cs
Normal file
92
Assets/Scripts/PauseMenu.cs
Normal file
|
@ -0,0 +1,92 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PauseMenu : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] GameObject pauseMenu;
|
||||
[SerializeField] GameObject mainPanel;
|
||||
[SerializeField] GameObject optionsPanel;
|
||||
[SerializeField] GameObject controlsPanel;
|
||||
[SerializeField] GameObject creditsPanel;
|
||||
[SerializeField] GameObject exitPanel;
|
||||
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
Pause();
|
||||
}
|
||||
}
|
||||
|
||||
private void Pause()
|
||||
{
|
||||
pauseMenu.SetActive(true);
|
||||
Time.timeScale = 0;
|
||||
}
|
||||
|
||||
public void Resume()
|
||||
{
|
||||
pauseMenu.SetActive(false);
|
||||
Time.timeScale = 1f;
|
||||
}
|
||||
|
||||
public void Options()
|
||||
{
|
||||
optionsPanel.SetActive(true);
|
||||
mainPanel.SetActive(false);
|
||||
}
|
||||
|
||||
public void Controls()
|
||||
{
|
||||
controlsPanel.SetActive(true);
|
||||
mainPanel.SetActive(false);
|
||||
}
|
||||
|
||||
public void Credits()
|
||||
{
|
||||
creditsPanel.SetActive(true);
|
||||
mainPanel.SetActive(false);
|
||||
}
|
||||
|
||||
public void Back()
|
||||
{
|
||||
if (creditsPanel.activeSelf)
|
||||
{
|
||||
creditsPanel.SetActive(false);
|
||||
}
|
||||
if (optionsPanel.activeSelf)
|
||||
{
|
||||
optionsPanel.SetActive(false);
|
||||
}
|
||||
if (controlsPanel.activeSelf)
|
||||
{
|
||||
controlsPanel.SetActive(false);
|
||||
}
|
||||
if (exitPanel.activeSelf)
|
||||
{
|
||||
exitPanel.SetActive(false);
|
||||
}
|
||||
mainPanel.SetActive(true);
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
exitPanel.SetActive(true);
|
||||
mainPanel.SetActive(false);
|
||||
}
|
||||
|
||||
public void GoToMainMenu()
|
||||
{
|
||||
//Change scene
|
||||
}
|
||||
|
||||
public void ExitGame()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
11
Assets/Scripts/PauseMenu.cs.meta
Normal file
11
Assets/Scripts/PauseMenu.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 806552b3bb4941145b7fd310f46617a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/SacksGame.meta
Normal file
8
Assets/Scripts/SacksGame.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 67967d1ccdf633e4ab9acd73552e9214
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
91
Assets/Scripts/SacksGame/SacksGameController.cs
Normal file
91
Assets/Scripts/SacksGame/SacksGameController.cs
Normal file
|
@ -0,0 +1,91 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
|
||||
public class SacksGameController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] ScenesTransitionController scenesTransition;
|
||||
|
||||
[SerializeField] List<SaltosSacosController> players;
|
||||
|
||||
[SerializeField] GameObject tutorialPanel;
|
||||
[SerializeField] GameObject countdownPanel;
|
||||
[SerializeField] GameObject gameOverPanel;
|
||||
|
||||
private GameObject winner;
|
||||
|
||||
[Header("Camera Settings")]
|
||||
[SerializeField] CinemachineVirtualCamera cameraGame;
|
||||
[SerializeField] CinemachineVirtualCamera cameraFinish;
|
||||
[SerializeField] float cinematicVelocity;
|
||||
|
||||
bool scoreDistributed;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
StartCoroutine(AudioManager.instance.FadeIn("transicion", 1));
|
||||
}
|
||||
|
||||
public void StartGame()
|
||||
{
|
||||
StartCoroutine(BeforeStartGame());
|
||||
}
|
||||
|
||||
|
||||
private IEnumerator BeforeStartGame()
|
||||
{
|
||||
//Fin Cinematica
|
||||
StartCoroutine(AudioManager.instance.FadeOut("transicion", 1));
|
||||
StartCoroutine(AudioManager.instance.FadeIn("06_sacos", 1));
|
||||
//AudioManager.instance.FadeIn("transicion", 1);
|
||||
|
||||
yield return new WaitForSecondsRealtime(0.5f);
|
||||
countdownPanel.SetActive(true);
|
||||
yield return new WaitForSecondsRealtime(4f);
|
||||
countdownPanel.SetActive(false);
|
||||
AudioManager.instance.PlayOneShot("SFX_silbato");
|
||||
foreach (SaltosSacosController player in players)
|
||||
{
|
||||
player.StartGame(this);
|
||||
}
|
||||
AudioManager.instance.FadeOut("transicion", 1);
|
||||
AudioManager.instance.FadeIn("06_sacos", 1);
|
||||
}
|
||||
|
||||
public void GameOver(GameObject _winner)
|
||||
{
|
||||
StartCoroutine(AudioManager.instance.FadeOut("06_sacos", 1));
|
||||
winner = _winner;
|
||||
foreach (SaltosSacosController player in players)
|
||||
{
|
||||
if (winner.Equals(player.gameObject))
|
||||
{
|
||||
if (player.GetIsPlayable())
|
||||
{
|
||||
AudioManager.instance.PlayOneShot("SFX_campanillas");
|
||||
}
|
||||
}
|
||||
}
|
||||
gameOverPanel.SetActive(true);
|
||||
cameraFinish.gameObject.SetActive(true);
|
||||
cameraGame.gameObject.SetActive(false);
|
||||
foreach (SaltosSacosController player in players)
|
||||
{
|
||||
player.GameOver();
|
||||
}
|
||||
|
||||
if (!scoreDistributed)
|
||||
{
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Sacks,
|
||||
winner.GetComponent<CharacterIdController>().CharacterId,
|
||||
scenesTransition,
|
||||
1.5f));
|
||||
|
||||
scoreDistributed = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/SacksGame/SacksGameController.cs.meta
Normal file
11
Assets/Scripts/SacksGame/SacksGameController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2fe34818e27db8d41b22b07f177508b7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
185
Assets/Scripts/SacksGame/SaltosSacosController.cs
Normal file
185
Assets/Scripts/SacksGame/SaltosSacosController.cs
Normal file
|
@ -0,0 +1,185 @@
|
|||
using System.CodeDom;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SaltosSacosController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] CharacterController controller = default;
|
||||
[SerializeField] public Animator anim;
|
||||
|
||||
[SerializeField] bool isPlayable;
|
||||
|
||||
[Header("Jump Settings")]
|
||||
[SerializeField, Min(0)] float jumpHeight;
|
||||
[SerializeField, Min(0)] float jumpDistance;
|
||||
[SerializeField, Min(0)] float jumpTime;
|
||||
[SerializeField] float gravity = -9.8f;
|
||||
|
||||
[Header("Detect Collisions")]
|
||||
[SerializeField] Transform groundCheck = default;
|
||||
[SerializeField, Range(0, .5f)] float groundDistance = .4f;
|
||||
[SerializeField]LayerMask groundMask;
|
||||
bool isGrounded;
|
||||
|
||||
[Header("Fall Settings")]
|
||||
[SerializeField] float fallingTime;
|
||||
|
||||
[Header("IA Settings")]
|
||||
[SerializeField, Min(0)] float maxDesviation;
|
||||
|
||||
Vector3 velocity;
|
||||
bool falling = false;
|
||||
bool gameFinished = false;
|
||||
bool gameStarted = false;
|
||||
|
||||
[SerializeField] MeshRenderer meshRenderer;
|
||||
[SerializeField] Material baseMaterial;
|
||||
[SerializeField] Material fallingMaterial;
|
||||
|
||||
private float timeOfJump;
|
||||
private float timeSinceJump;
|
||||
|
||||
private SacksGameController gameController;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if(gameObject.CompareTag("Player"))
|
||||
anim = GetComponent<CharacterIdController>().SetPlayerCustom();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (isPlayable && gameStarted && !gameFinished)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.W))
|
||||
{
|
||||
CheckJump();
|
||||
}
|
||||
}
|
||||
if (!IsGrounded())
|
||||
{
|
||||
velocity.y += gravity * Time.deltaTime;
|
||||
controller.Move(velocity * Time.deltaTime);
|
||||
timeOfJump += Time.deltaTime;
|
||||
} else
|
||||
{
|
||||
timeOfJump = 0;
|
||||
velocity.y = -4f;
|
||||
controller.Move(velocity * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetIsPlayable()
|
||||
{
|
||||
return isPlayable;
|
||||
}
|
||||
|
||||
private void CheckJump()
|
||||
{
|
||||
if (IsGrounded())
|
||||
{
|
||||
if (!falling)
|
||||
{
|
||||
Jump();
|
||||
}
|
||||
} else
|
||||
{
|
||||
Fall();
|
||||
}
|
||||
}
|
||||
|
||||
private void Fall()
|
||||
{
|
||||
StartCoroutine(FallCoroutine());
|
||||
}
|
||||
|
||||
private void Jump()
|
||||
{
|
||||
StartCoroutine(JumpCoroutine());
|
||||
if (isPlayable)
|
||||
{
|
||||
AudioManager.instance.PlayOneShot("SFX_saltoSacos" + Random.Range(1, 5), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
AudioManager.instance.PlayOneShot("SFX_saltoSacosEnemigos", true);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator JumpCoroutine()
|
||||
{
|
||||
float i = 0;
|
||||
while (i < jumpTime)
|
||||
{
|
||||
anim.SetTrigger("SacksJump");
|
||||
Vector3 jumpVelocity = new Vector3(jumpDistance, jumpHeight, 0);
|
||||
controller.Move(jumpVelocity * Time.deltaTime);
|
||||
i += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator FallCoroutine()
|
||||
{
|
||||
falling = true;
|
||||
meshRenderer.material = fallingMaterial;
|
||||
yield return new WaitForSecondsRealtime(fallingTime);
|
||||
meshRenderer.material = baseMaterial;
|
||||
falling = false;
|
||||
}
|
||||
|
||||
private IEnumerator IA_Jump()
|
||||
{
|
||||
Debug.Log("IA Jump Started");
|
||||
float firstWait = Random.Range(0.1f, 0.3f);
|
||||
yield return new WaitForSecondsRealtime(firstWait);
|
||||
while (!gameFinished)
|
||||
{
|
||||
float totalTimeToWait = jumpTime;
|
||||
int desviation = Random.Range(0,14);
|
||||
float timeToWait = 0;
|
||||
if (desviation > 0)
|
||||
{
|
||||
timeToWait = Random.Range(0.12f, 0.15f);
|
||||
totalTimeToWait += timeToWait;
|
||||
} else
|
||||
{
|
||||
timeToWait = Random.Range(0.05f, 0.1f);
|
||||
totalTimeToWait += timeToWait;
|
||||
}
|
||||
CheckJump();
|
||||
yield return new WaitForSecondsRealtime(totalTimeToWait);
|
||||
}
|
||||
}
|
||||
|
||||
public void StartGame(SacksGameController controller)
|
||||
{
|
||||
gameController = controller;
|
||||
gameStarted = true;
|
||||
if (isPlayable == false)
|
||||
{
|
||||
StartCoroutine(IA_Jump());
|
||||
}
|
||||
}
|
||||
|
||||
public void GameOver()
|
||||
{
|
||||
gameFinished = true;
|
||||
|
||||
}
|
||||
|
||||
private bool IsGrounded()
|
||||
{
|
||||
return Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("FinishLine"))
|
||||
{
|
||||
gameController.GameOver(this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/SacksGame/SaltosSacosController.cs.meta
Normal file
11
Assets/Scripts/SacksGame/SaltosSacosController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 60308fa1c544a1142b6f9ab9d2a9b3bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
20
Assets/Scripts/ScenesTransitionController.cs
Normal file
20
Assets/Scripts/ScenesTransitionController.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class ScenesTransitionController : MonoBehaviour
|
||||
{
|
||||
|
||||
public void CloseScene(string newSceneName)
|
||||
{
|
||||
GetComponent<Animator>().SetTrigger("closeBox");
|
||||
StartCoroutine(LoadNewScene(newSceneName));
|
||||
}
|
||||
IEnumerator LoadNewScene(string newSceneName)
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(1.05f);
|
||||
SceneManager.LoadSceneAsync(newSceneName);
|
||||
Time.timeScale = 1;
|
||||
}
|
||||
}
|
11
Assets/Scripts/ScenesTransitionController.cs.meta
Normal file
11
Assets/Scripts/ScenesTransitionController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5e65b016cb43f194ca0fd1c49561ca99
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
63
Assets/Scripts/ScoreCounter.cs
Normal file
63
Assets/Scripts/ScoreCounter.cs
Normal file
|
@ -0,0 +1,63 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ScoreCounter : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] List<GameObject> scores;
|
||||
|
||||
[SerializeField] List<int> scorePoints;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
StartCoroutine(StartScoreCount());
|
||||
}
|
||||
|
||||
IEnumerator StartScoreCount()
|
||||
{
|
||||
BetweenScenePass data = BetweenScenePass.instance;
|
||||
|
||||
yield return new WaitUntil(() => data != null);
|
||||
|
||||
for (int i = 0; i < data.CharacterScore[BetweenScenePass.Games.Swords].Count; i++)
|
||||
{
|
||||
scorePoints[i] += data.CharacterScore[BetweenScenePass.Games.Swords][i];
|
||||
}
|
||||
for (int i = 0; i < data.CharacterScore[BetweenScenePass.Games.Sacks].Count; i++)
|
||||
{
|
||||
scorePoints[i] += data.CharacterScore[BetweenScenePass.Games.Sacks][i];
|
||||
}
|
||||
for (int i = 0; i < data.CharacterScore[BetweenScenePass.Games.Chairs].Count; i++)
|
||||
{
|
||||
scorePoints[i] += data.CharacterScore[BetweenScenePass.Games.Chairs][i];
|
||||
}
|
||||
for (int i = 0; i < data.CharacterScore[BetweenScenePass.Games.Jousting].Count; i++)
|
||||
{
|
||||
scorePoints[i] += data.CharacterScore[BetweenScenePass.Games.Jousting][i];
|
||||
}
|
||||
for (int i = 0; i < data.CharacterScore[BetweenScenePass.Games.Baloons].Count; i++)
|
||||
{
|
||||
scorePoints[i] += data.CharacterScore[BetweenScenePass.Games.Baloons][i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
for (int j = 0; j < scorePoints[i]; j++)
|
||||
{
|
||||
if (scores[i].transform.childCount >= j) {
|
||||
scores[i].transform.GetChild(j).gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/ScoreCounter.cs.meta
Normal file
11
Assets/Scripts/ScoreCounter.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7cec5f4cc2e288a41a575f7b0e9eba05
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/SwordsGame.meta
Normal file
8
Assets/Scripts/SwordsGame.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8ec340cd1b043284786fe11825d24c12
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
58
Assets/Scripts/SwordsGame/SwordAttack.cs
Normal file
58
Assets/Scripts/SwordsGame/SwordAttack.cs
Normal file
|
@ -0,0 +1,58 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SwordAttack : MonoBehaviour{
|
||||
[SerializeField] GameTutorialControler tutorial;
|
||||
[SerializeField] float attackDamage = 20f;
|
||||
Animator anim;
|
||||
|
||||
[Space]
|
||||
[SerializeField] Transform attackPos = default;
|
||||
[SerializeField, Range(0, 3)] float attackRange = 2;
|
||||
[SerializeField] LayerMask whatIsEnemy = -1;
|
||||
|
||||
SwordPlayerController player;
|
||||
bool attacking;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
anim = GetComponent<Animator>();
|
||||
player = FindObjectOfType<SwordPlayerController>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (Input.GetMouseButtonDown(0) && !attacking && tutorial.gameStarted)
|
||||
{
|
||||
anim.SetTrigger("Attack");
|
||||
attacking = true;
|
||||
player.StopMovement();
|
||||
}
|
||||
}
|
||||
|
||||
public void Attack(){
|
||||
Collider[] hitEnemies = Physics.OverlapSphere(attackPos.position, attackRange, whatIsEnemy);
|
||||
|
||||
if(hitEnemies.Length == 0)
|
||||
AudioManager.instance.PlayOneShot("SFX_falloEspada" + Random.Range(1, 5), true);
|
||||
else
|
||||
AudioManager.instance.PlayOneShot("SFX_Espada" + Random.Range(1, 3), true);
|
||||
|
||||
foreach (Collider enemy in hitEnemies){
|
||||
enemy.GetComponent<SwordsEnemyController>().Damage(attackDamage);
|
||||
}
|
||||
}
|
||||
|
||||
public void EndAttack(){
|
||||
attacking = false;
|
||||
player.RegainMovement();
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
if (attackPos == null)
|
||||
return;
|
||||
|
||||
Gizmos.DrawWireSphere(attackPos.position, attackRange);
|
||||
}
|
||||
}
|
11
Assets/Scripts/SwordsGame/SwordAttack.cs.meta
Normal file
11
Assets/Scripts/SwordsGame/SwordAttack.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a8104ba5c10fdd34685410ad7135f5a8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
10
Assets/Scripts/SwordsGame/SwordCharacterType.cs
Normal file
10
Assets/Scripts/SwordsGame/SwordCharacterType.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
[System.Serializable]
|
||||
public class SwordCharacterType{
|
||||
|
||||
public float speed;
|
||||
|
||||
public float detectArea;
|
||||
|
||||
public float angryIncreaseTime;
|
||||
public float healthAlert;
|
||||
}
|
11
Assets/Scripts/SwordsGame/SwordCharacterType.cs.meta
Normal file
11
Assets/Scripts/SwordsGame/SwordCharacterType.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3efba04bd5a56534986a6fb05d3b2525
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
64
Assets/Scripts/SwordsGame/SwordEnemyAttack.cs
Normal file
64
Assets/Scripts/SwordsGame/SwordEnemyAttack.cs
Normal file
|
@ -0,0 +1,64 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class SwordEnemyAttack : MonoBehaviour{
|
||||
|
||||
[SerializeField] Animator anim = default;
|
||||
[SerializeField] float attackDamage = 20f;
|
||||
[SerializeField, Range(0, .5f)] float attackMaxDelay = .1f;
|
||||
bool attacking;
|
||||
|
||||
[SerializeField] NavMeshAgent agent;
|
||||
|
||||
[Space]
|
||||
[SerializeField] Transform attackPos = default;
|
||||
[SerializeField, Range(0, 3)] float attackRange = 2;
|
||||
[SerializeField] LayerMask whatIsEnemy = -1;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Update(){
|
||||
Collider[] hitEnemies = Physics.OverlapSphere(attackPos.position, attackRange, whatIsEnemy);
|
||||
if (hitEnemies.Length > 0 && !attacking)
|
||||
{
|
||||
if (GetComponentInParent<SwordsEnemyController>().hp > 0f) {
|
||||
attacking = true;
|
||||
anim.SetTrigger("Attack");
|
||||
}
|
||||
}
|
||||
|
||||
if (attacking)
|
||||
{
|
||||
agent.isStopped = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
agent.isStopped = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Attack(){
|
||||
Collider[] hitEnemies = Physics.OverlapSphere(attackPos.position, attackRange, whatIsEnemy);
|
||||
|
||||
if (hitEnemies.Length == 0)
|
||||
AudioManager.instance.PlayOneShot("SFX_falloEspada" + Random.Range(1, 5));
|
||||
else
|
||||
AudioManager.instance.PlayOneShot("SFX_Espada" + Random.Range(1, 3));
|
||||
|
||||
foreach (Collider enemy in hitEnemies){
|
||||
enemy.GetComponent<SwordPlayerController>().Damage(attackDamage);
|
||||
}
|
||||
}
|
||||
|
||||
public void EndAttack(){
|
||||
attacking = false;
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
if (attackPos == null)
|
||||
return;
|
||||
|
||||
Gizmos.DrawWireSphere(attackPos.position, attackRange);
|
||||
}
|
||||
}
|
11
Assets/Scripts/SwordsGame/SwordEnemyAttack.cs.meta
Normal file
11
Assets/Scripts/SwordsGame/SwordEnemyAttack.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 46fe85b04190be54583da24a5beb8ed2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
218
Assets/Scripts/SwordsGame/SwordPlayerController.cs
Normal file
218
Assets/Scripts/SwordsGame/SwordPlayerController.cs
Normal file
|
@ -0,0 +1,218 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SwordPlayerController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] ScenesTransitionController scenesTransition = default;
|
||||
[SerializeField] GameTutorialControler tutorial = default;
|
||||
[SerializeField] Animator anim = default;
|
||||
[SerializeField] public Animator charAnim = default;
|
||||
[SerializeField] CharacterController controller = default;
|
||||
[SerializeField] Transform cam = default;
|
||||
[SerializeField] Transform enemy = default;
|
||||
|
||||
[SerializeField] float speed = 6;
|
||||
|
||||
[SerializeField, Range(0, .3f)] float turnSmoothTime = .1f;
|
||||
float turnSmoothVelocity;
|
||||
|
||||
[Header("Jump")]
|
||||
[SerializeField, Min(0)] float gravity = 15f;
|
||||
[SerializeField] float jumpHeight = 3f;
|
||||
[SerializeField, Range(0, .5f)] float jumpDelay = .5f;
|
||||
Vector3 velocity;
|
||||
|
||||
[SerializeField] Transform groundCheck = default;
|
||||
[SerializeField, Range(0, .5f)] float groundDistance = .4f;
|
||||
[SerializeField] LayerMask groundMask = -1;
|
||||
bool isGrounded;
|
||||
|
||||
[Space]
|
||||
[SerializeField] Image healthBar = default;
|
||||
[SerializeField] float maxHp = 100;
|
||||
float hp;
|
||||
bool canMove;
|
||||
|
||||
[Space]
|
||||
[SerializeField] GameObject playerHPbar;
|
||||
[SerializeField] GameObject enemyHPbar;
|
||||
[SerializeField] GameObject playerHPbarLabel;
|
||||
[SerializeField] GameObject enemyHPbarLabel;
|
||||
|
||||
[SerializeField, Range(0, 1f)] float stepsInterval = .5f;
|
||||
float currentTime;
|
||||
|
||||
bool scoreDistributed;
|
||||
|
||||
void Awake(){
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
hp = maxHp;
|
||||
canMove = true;
|
||||
|
||||
charAnim = GetComponent<CharacterIdController>().SetPlayerCustom();
|
||||
}
|
||||
|
||||
float currentX;
|
||||
float xDirVelocity;
|
||||
float currentY;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (tutorial.gameStarted)
|
||||
{
|
||||
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
|
||||
|
||||
if (isGrounded && velocity.y < 0)
|
||||
{
|
||||
velocity.y = -2f;
|
||||
}
|
||||
|
||||
float horizontal = Input.GetAxisRaw("Horizontal");
|
||||
float vertical = Input.GetAxisRaw("Vertical");
|
||||
Vector3 direction = new Vector3(horizontal, 0, vertical).normalized;
|
||||
|
||||
if (direction.magnitude >= .1f && canMove)
|
||||
{
|
||||
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
|
||||
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
|
||||
transform.rotation = Quaternion.Euler(0, angle, 0);
|
||||
|
||||
Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
|
||||
controller.Move(moveDir.normalized * speed * Time.deltaTime);
|
||||
|
||||
Vector3 directionX = direction.x * transform.forward;
|
||||
Vector3 directionZ = direction.z * transform.forward;
|
||||
currentX = Mathf.SmoothDamp(currentX, directionX.x, ref xDirVelocity, .1f);
|
||||
currentY = Mathf.SmoothDamp(currentY, directionZ.z, ref xDirVelocity, .1f);
|
||||
charAnim.SetFloat("VelocityY", 1);
|
||||
anim.SetBool("Moving", true);
|
||||
|
||||
currentTime += Time.deltaTime;
|
||||
if (currentTime >= stepsInterval)
|
||||
{
|
||||
AudioManager.instance.PlayOneShot("SFX_paso" + Random.Range(1, 6), true);
|
||||
currentTime = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
currentX = Mathf.SmoothDamp(currentX, 0, ref xDirVelocity, .1f);
|
||||
currentY = Mathf.SmoothDamp(currentY, 0, ref xDirVelocity, .1f);
|
||||
charAnim.SetFloat("VelocityY", 0);
|
||||
anim.SetBool("Moving", false);
|
||||
}
|
||||
|
||||
velocity.y -= gravity * Time.deltaTime;
|
||||
controller.Move(velocity * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void StopMovement(){
|
||||
transform.LookAt(new Vector3(enemy.position.x, transform.position.y, enemy.position.z));
|
||||
canMove = false;
|
||||
}
|
||||
|
||||
public void RegainMovement(){
|
||||
if(hp > 0){
|
||||
canMove = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Damage(float ammount){
|
||||
if(hp > 0){
|
||||
hp -= ammount;
|
||||
healthBar.transform.localScale = new Vector3(Mathf.Clamp(hp / maxHp, 0, 1), 1, 1);
|
||||
|
||||
ScreenShakeCall.instance.ShakeCamera(12.5f, .4f);
|
||||
|
||||
if (hp > 0f){
|
||||
charAnim.SetTrigger("Damage");
|
||||
float randomAnim = Random.Range(0, 200);
|
||||
if(randomAnim > 100){
|
||||
GameObject pow = ObjectPooler.instance.SpawnFromPool("Pow", transform.position + Vector3.up);
|
||||
pow.transform.LookAt(cam);
|
||||
}
|
||||
else{
|
||||
GameObject pam = ObjectPooler.instance.SpawnFromPool("Pam", transform.position + Vector3.up);
|
||||
pam.transform.LookAt(cam);
|
||||
}
|
||||
}else{
|
||||
GameObject kapow = ObjectPooler.instance.SpawnFromPool("Kapow", transform.position);
|
||||
kapow.transform.LookAt(Camera.main.transform);
|
||||
charAnim.SetTrigger("Die");
|
||||
StopMovement();
|
||||
ReturnToMenu(GameObject.Find("Enemy").GetComponent<CharacterIdController>().CharacterId, gameObject.GetComponent<CharacterIdController>().CharacterId);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
if(groundCheck != null){
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireSphere(groundCheck.position, groundDistance);
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowLives()
|
||||
{
|
||||
playerHPbar.SetActive(true);
|
||||
enemyHPbar.SetActive(true);
|
||||
playerHPbarLabel.SetActive(true);
|
||||
enemyHPbarLabel.SetActive(true);
|
||||
|
||||
StartCoroutine(AudioManager.instance.FadeOut("transicion", 1));
|
||||
StartCoroutine(AudioManager.instance.FadeIn("04_espadas", 1));
|
||||
}
|
||||
|
||||
void ReturnToMenu(int winner, int looser)
|
||||
{
|
||||
if (!scoreDistributed)
|
||||
{
|
||||
//AudioManager.instance.PlayOneShot("SFX_booring");
|
||||
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Swords,
|
||||
winner,
|
||||
null));
|
||||
|
||||
int newWinner1 = winner;
|
||||
int i = 0;
|
||||
while (i < 100)
|
||||
{
|
||||
newWinner1 = Random.Range(0, 6);
|
||||
i++;
|
||||
if (newWinner1 != winner && newWinner1 != looser)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Swords,
|
||||
newWinner1,
|
||||
null));
|
||||
|
||||
int newWinner2;
|
||||
newWinner2 = winner;
|
||||
i = 0;
|
||||
while (i < 100)
|
||||
{
|
||||
newWinner2 = Random.Range(0, 6);
|
||||
i++;
|
||||
if (newWinner2 != winner && newWinner2 != looser && newWinner2 != newWinner1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Swords,
|
||||
newWinner2,
|
||||
scenesTransition));
|
||||
scoreDistributed = true;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/SwordsGame/SwordPlayerController.cs.meta
Normal file
11
Assets/Scripts/SwordsGame/SwordPlayerController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6db0af3c8c50c204eabd60264e312957
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
175
Assets/Scripts/SwordsGame/SwordsEnemyController.cs
Normal file
175
Assets/Scripts/SwordsGame/SwordsEnemyController.cs
Normal file
|
@ -0,0 +1,175 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SwordsEnemyController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] ScenesTransitionController scenesTransition = default;
|
||||
[SerializeField] GameTutorialControler tutorial = default;
|
||||
[SerializeField] Transform player = default;
|
||||
NavMeshAgent agent;
|
||||
[SerializeField] Animator charAnim = default;
|
||||
|
||||
[System.Serializable] public enum Personality {Shy, Hyperactive, Balanced}
|
||||
[Space]
|
||||
public Personality personality;
|
||||
|
||||
[SerializeField] float maxHp = 100;
|
||||
public float hp;
|
||||
|
||||
[SerializeField] float currentRadius = 10;
|
||||
[SerializeField, Range(0, 3)] float angryLevel;
|
||||
float angryLevelIncreaseTime;
|
||||
[SerializeField] float healthAlert;
|
||||
|
||||
[Space]
|
||||
[SerializeField] SwordCharacterType shyStats = default;
|
||||
[SerializeField] SwordCharacterType angryStats = default;
|
||||
[SerializeField] SwordCharacterType balancedStats = default;
|
||||
|
||||
[Space]
|
||||
[SerializeField] Image healthBar = default;
|
||||
|
||||
[SerializeField, Range(0, 1f)] float stepsInterval = .5f;
|
||||
float currentTime;
|
||||
|
||||
bool scoreDistributed;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
|
||||
charAnim = charAnim = GetComponent<CharacterIdController>().SetRandomNpcCustom();
|
||||
|
||||
|
||||
agent = GetComponent<NavMeshAgent>();
|
||||
switch (personality){
|
||||
case Personality.Balanced:
|
||||
currentRadius = balancedStats.detectArea;
|
||||
healthAlert = balancedStats.healthAlert;
|
||||
angryLevelIncreaseTime = balancedStats.angryIncreaseTime;
|
||||
agent.speed = balancedStats.speed;
|
||||
break;
|
||||
case Personality.Hyperactive:
|
||||
currentRadius = angryStats.detectArea;
|
||||
healthAlert = angryStats.healthAlert;
|
||||
angryLevelIncreaseTime = angryStats.angryIncreaseTime;
|
||||
agent.speed = angryStats.speed;
|
||||
break;
|
||||
case Personality.Shy:
|
||||
currentRadius = shyStats.detectArea;
|
||||
healthAlert = shyStats.healthAlert;
|
||||
angryLevelIncreaseTime = shyStats.angryIncreaseTime;
|
||||
agent.speed = shyStats.speed;
|
||||
break;
|
||||
}
|
||||
|
||||
hp = maxHp;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if (tutorial.gameStarted)
|
||||
{
|
||||
agent.SetDestination(new Vector3(player.position.x, 0, player.position.z));
|
||||
|
||||
if ((player.position - transform.position).sqrMagnitude < agent.stoppingDistance * agent.stoppingDistance)
|
||||
{
|
||||
transform.LookAt(new Vector3(player.position.x, transform.position.y, player.position.z));
|
||||
}
|
||||
|
||||
charAnim.SetFloat("VelocityY", 1);
|
||||
|
||||
currentTime += Time.deltaTime;
|
||||
if (currentTime >= stepsInterval)
|
||||
{
|
||||
AudioManager.instance.PlayOneShot("SFX_paso" + Random.Range(1, 6), true);
|
||||
currentTime = 0;
|
||||
}
|
||||
|
||||
angryLevel += angryLevelIncreaseTime * Time.deltaTime;
|
||||
angryLevel = Mathf.Clamp(angryLevel, 0, 3);
|
||||
}
|
||||
}
|
||||
|
||||
public void Damage(float amount){
|
||||
if (hp > 0){
|
||||
hp -= amount;
|
||||
healthBar.transform.localScale = new Vector3(Mathf.Clamp(hp / maxHp, 0, 1), 1, 1);
|
||||
|
||||
ScreenShakeCall.instance.ShakeCamera(12.5f, .4f);
|
||||
|
||||
if (hp > 0f){
|
||||
float randomAnim = Random.Range(0, 200);
|
||||
if (randomAnim > 100){
|
||||
GameObject pow = ObjectPooler.instance.SpawnFromPool("Pow", transform.position + Vector3.up);
|
||||
pow.transform.LookAt(Camera.main.transform);
|
||||
}else{
|
||||
GameObject pam = ObjectPooler.instance.SpawnFromPool("Pam", transform.position + Vector3.up);
|
||||
pam.transform.LookAt(Camera.main.transform);
|
||||
}
|
||||
charAnim.SetTrigger("Damage");
|
||||
}else{
|
||||
GameObject kapow = ObjectPooler.instance.SpawnFromPool("Kapow", transform.position);
|
||||
kapow.transform.LookAt(Camera.main.transform);
|
||||
charAnim.SetTrigger("Die");
|
||||
ReturnToMenu(GameObject.Find("Player").GetComponent<CharacterIdController>().CharacterId, gameObject.GetComponent<CharacterIdController>().CharacterId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnDrawGizmosSelected(){
|
||||
Gizmos.DrawWireSphere(transform.position, currentRadius);
|
||||
}
|
||||
|
||||
void ReturnToMenu(int winner, int looser)
|
||||
{
|
||||
if (!scoreDistributed)
|
||||
{
|
||||
AudioManager.instance.PlayOneShot("SFX_campanillas");
|
||||
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Swords,
|
||||
winner,
|
||||
null));
|
||||
|
||||
int newWinner1 = winner;
|
||||
int i = 0;
|
||||
while (i < 100)
|
||||
{
|
||||
newWinner1 = Random.Range(0, 6);
|
||||
i++;
|
||||
if (newWinner1 != winner && newWinner1 != looser)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Swords,
|
||||
newWinner1,
|
||||
null));
|
||||
|
||||
int newWinner2;
|
||||
newWinner2 = winner;
|
||||
i = 0;
|
||||
while (i < 100)
|
||||
{
|
||||
newWinner2 = Random.Range(0, 6);
|
||||
i++;
|
||||
if (newWinner2 != winner && newWinner2 != looser && newWinner2 != newWinner1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
StartCoroutine(BetweenScenePass.instance.DistributeScore(
|
||||
BetweenScenePass.Games.Swords,
|
||||
newWinner2,
|
||||
scenesTransition));
|
||||
scoreDistributed = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/SwordsGame/SwordsEnemyController.cs.meta
Normal file
11
Assets/Scripts/SwordsGame/SwordsEnemyController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 279d3c70f1b27c74d9ba8001aed01660
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
74
Assets/Scripts/TextMovement.cs
Normal file
74
Assets/Scripts/TextMovement.cs
Normal file
|
@ -0,0 +1,74 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
[RequireComponent(typeof(TextMeshProUGUI))]
|
||||
public class TextMovement : MonoBehaviour
|
||||
{
|
||||
enum movementType { ThreeSecondsCountdown };
|
||||
[SerializeField] private movementType type;
|
||||
[SerializeField] private float velocity;
|
||||
[SerializeField] private float desiredValue;
|
||||
|
||||
private float originalFontSize;
|
||||
|
||||
private TextMeshProUGUI text;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
text = this.gameObject.GetComponent<TextMeshProUGUI>();
|
||||
originalFontSize = text.fontSize;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
//text = this.gameObject.GetComponent<TextMeshProUGUI>();
|
||||
text.fontSize = originalFontSize;
|
||||
switch (type)
|
||||
{
|
||||
case movementType.ThreeSecondsCountdown:
|
||||
StartCoroutine(ThreeSecondsCountDown(velocity, desiredValue));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator ThreeSecondsCountDown(float velocity, float desiredValue)
|
||||
{
|
||||
float original = text.fontSize;
|
||||
float limit = 1.5f;
|
||||
for (int a = 3; a > 0; a--) {
|
||||
text.fontSize = original;
|
||||
text.text = a.ToString();
|
||||
float i = 0;
|
||||
bool increasing = true;
|
||||
while (i < limit)
|
||||
{
|
||||
if (increasing)
|
||||
{
|
||||
text.fontSize += velocity * Time.deltaTime;
|
||||
if (text.fontSize >= desiredValue)
|
||||
{
|
||||
text.fontSize = desiredValue;
|
||||
increasing = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
text.fontSize -= velocity * Time.deltaTime;
|
||||
if (text.fontSize <= original)
|
||||
{
|
||||
text.fontSize = original;
|
||||
increasing = true;
|
||||
}
|
||||
}
|
||||
i+= Time.smoothDeltaTime;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
text.fontSize = original;
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/TextMovement.cs.meta
Normal file
11
Assets/Scripts/TextMovement.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bd700a483a7fed949ac184487c8b3992
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Tools.meta
Normal file
8
Assets/Scripts/Tools.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0e3d35b82637e8d4db4d42317ab21bfb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Tools/AudioManager.meta
Normal file
8
Assets/Scripts/Tools/AudioManager.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 725f4ce889158f74f926c423d93bf165
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
236
Assets/Scripts/Tools/AudioManager/AudioManager.cs
Normal file
236
Assets/Scripts/Tools/AudioManager/AudioManager.cs
Normal file
|
@ -0,0 +1,236 @@
|
|||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine.Audio;
|
||||
using System.Collections;
|
||||
|
||||
public class AudioManager : MonoBehaviour{
|
||||
|
||||
[Tooltip("The music mixer.")]
|
||||
[SerializeField] AudioMixerGroup mainMixer = default;
|
||||
[Tooltip("The SFX mixer.")]
|
||||
[SerializeField] AudioMixerGroup sfxMixer = default;
|
||||
|
||||
[Space]
|
||||
[SerializeField] Sound[] sounds = default;
|
||||
|
||||
public static AudioManager instance;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
if (instance == null){
|
||||
instance = this;
|
||||
}else{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
foreach (Sound s in sounds){
|
||||
s.source = gameObject.AddComponent<AudioSource>();
|
||||
|
||||
if(s.type == Sound.Type.Music)
|
||||
s.source.outputAudioMixerGroup = mainMixer;
|
||||
else
|
||||
s.source.outputAudioMixerGroup = sfxMixer;
|
||||
|
||||
s.source.clip = s.clip;
|
||||
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
s.source.loop = s.loop;
|
||||
s.source.playOnAwake = false;
|
||||
}
|
||||
}
|
||||
|
||||
#region Play
|
||||
/// <summary> Play a sound with a certain name setted on the inspector. </summary>
|
||||
public void Play(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
s.source.Play();
|
||||
}
|
||||
|
||||
/// <summary> Play a sound with a certain name setted on the inspector.
|
||||
/// Set the randomPitch to true to make the sound start with a random pitch variation setted on the inspector. </summary>
|
||||
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));
|
||||
}else{
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
}
|
||||
s.source.PlayOneShot(s.clip);
|
||||
}
|
||||
|
||||
/// <summary> Play a sound with a certain name setted on the inspector.
|
||||
/// Make the sound start with a certain delay. </summary>
|
||||
public void Play(string name, float delay){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
s.source.PlayDelayed(delay);
|
||||
}
|
||||
|
||||
/// <summary> Play a sound with a certain name setted on the inspector.
|
||||
/// Play it with a randomPitch and delay. </summary>
|
||||
public void Play(string name, float delay, 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));
|
||||
}else{
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
}
|
||||
s.source.PlayDelayed(delay);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region PlayOneShot
|
||||
/// <summary> Play a sound with a certain name without overlapping. </summary>
|
||||
public void PlayOneShot(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
s.source.PlayOneShot(s.clip);
|
||||
}
|
||||
|
||||
/// <summary> Play a sound with a certain name without overlapping.
|
||||
/// Set the randomPitch to true to make the sound start with a random pitch variation setted on the inspector. </summary>
|
||||
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));
|
||||
}else{
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
}
|
||||
s.source.PlayOneShot(s.clip);
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary> Pause a sound with a certain name setted on the inspector. </summary>
|
||||
public void Pause(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.Pause();
|
||||
}
|
||||
|
||||
/// <summary> Unpause a sound with a certain name setted on the inspector. </summary>
|
||||
public void UnPause(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.UnPause();
|
||||
}
|
||||
|
||||
/// <summary> Stop a sound with a certain name setted on the inspector. </summary>
|
||||
public void Stop(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.Stop();
|
||||
}
|
||||
|
||||
public void StopAll(){
|
||||
foreach(Sound s in sounds){
|
||||
if(s.source != null){
|
||||
s.source.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AudioSource GetSource(string name)
|
||||
{
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null)
|
||||
{
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return null;
|
||||
}
|
||||
|
||||
return s.source;
|
||||
}
|
||||
|
||||
public IEnumerator FadeOut(string name, float FadeTime)
|
||||
{
|
||||
AudioSource audioSource = GetSource(name);
|
||||
if (audioSource != null && audioSource.isPlaying)
|
||||
{
|
||||
float startVolume = audioSource.volume;
|
||||
|
||||
while (audioSource.volume > 0)
|
||||
{
|
||||
audioSource.volume -= startVolume * Time.deltaTime / FadeTime;
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
audioSource.Stop();
|
||||
audioSource.volume = startVolume;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator FadeIn(string name, float FadeTime)
|
||||
{
|
||||
AudioSource audioSource = GetSource(name);
|
||||
if (audioSource != null && !audioSource.isPlaying)
|
||||
{
|
||||
float volume = audioSource.volume;
|
||||
audioSource.volume = 0;
|
||||
audioSource.Play();
|
||||
|
||||
while (audioSource.volume < volume)
|
||||
{
|
||||
audioSource.volume += Time.deltaTime / FadeTime;
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tools/AudioManager/AudioManager.cs.meta
Normal file
11
Assets/Scripts/Tools/AudioManager/AudioManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ebdca66b03709e04097142c1a3259b26
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
25
Assets/Scripts/Tools/AudioManager/Sound.cs
Normal file
25
Assets/Scripts/Tools/AudioManager/Sound.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class Sound{
|
||||
[Tooltip("Name of the sound. Each name has to be different between each other.")]
|
||||
public string name;
|
||||
|
||||
public AudioClip clip;
|
||||
|
||||
[System.Serializable] public enum Type {Music, SFX}
|
||||
[Space]
|
||||
[Tooltip("Is it part of the music or the SFX?")] public Type type;
|
||||
|
||||
[Space]
|
||||
[Tooltip("Default volume of the sound.")] [Range(0f, 1f)] public float volume = 1;
|
||||
[Tooltip("Max random volume variation of the sound.")] [Range(0f, 1f)] public float volumeVariance;
|
||||
[Space]
|
||||
[Tooltip("Default pitch of the sound.")] [Range(.1f, 3f)] public float pitch = 1;
|
||||
[Tooltip("Max random pitch variation of the sound.")] [Range(0f, 1f)] public float pitchVariance;
|
||||
|
||||
public bool loop;
|
||||
|
||||
[HideInInspector] public AudioSource source;
|
||||
}
|
||||
|
11
Assets/Scripts/Tools/AudioManager/Sound.cs.meta
Normal file
11
Assets/Scripts/Tools/AudioManager/Sound.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 515e53d16f5b80c4f9bca8a800703033
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Tools/Cinemachine.meta
Normal file
8
Assets/Scripts/Tools/Cinemachine.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b63526de6c0bdef48ae6fa84ece57017
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
27
Assets/Scripts/Tools/Cinemachine/CMCameraTrigger.cs
Normal file
27
Assets/Scripts/Tools/Cinemachine/CMCameraTrigger.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
|
||||
public class CMCameraTrigger : MonoBehaviour{
|
||||
|
||||
CinemachineVirtualCamera vcam;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
vcam = GetComponentInChildren<CinemachineVirtualCamera>();
|
||||
vcam.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D col){
|
||||
if (col.CompareTag("Player")){
|
||||
vcam.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
void OnTriggerExit2D(Collider2D col){
|
||||
if (col.CompareTag("Player")){
|
||||
vcam.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tools/Cinemachine/CMCameraTrigger.cs.meta
Normal file
11
Assets/Scripts/Tools/Cinemachine/CMCameraTrigger.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 368758c1440a4cb4c867e140e8934c09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 64770ab13b014f446bb4ad495e0b508c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,121 @@
|
|||
using Cinemachine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
[System.Serializable] public class EndCutscene : UnityEvent { }
|
||||
|
||||
public class CMCameraRail : MonoBehaviour{
|
||||
|
||||
[SerializeField] CinemachineVirtualCamera dollyTrackCamera = default;
|
||||
CinemachineTrackedDolly cameraTrack;
|
||||
|
||||
[Space]
|
||||
[SerializeField] Waypoint[] waypoints = default;
|
||||
int totalCount;
|
||||
int currentCount;
|
||||
|
||||
bool finished;
|
||||
bool paused;
|
||||
|
||||
float easedPercentBetweenWaypoints;
|
||||
float speed;
|
||||
float currentEase;
|
||||
float percentBetweenWaypoints;
|
||||
float nextPos;
|
||||
float lastFieldOfView;
|
||||
|
||||
[Space]
|
||||
public EndCutscene onCutsceneEnd;
|
||||
|
||||
void Awake(){
|
||||
paused = true;
|
||||
lastFieldOfView = dollyTrackCamera.m_Lens.FieldOfView;
|
||||
totalCount = waypoints.Length - 1;
|
||||
if(dollyTrackCamera != null){
|
||||
cameraTrack = dollyTrackCamera.GetCinemachineComponent<CinemachineTrackedDolly>();
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
if(!finished && !paused){
|
||||
Waypoint waypoint = waypoints[currentCount];
|
||||
|
||||
if(currentCount == 0){
|
||||
speed = Time.deltaTime / waypoint.timeBetweenWaypoints * waypoint.endWaypoint;
|
||||
percentBetweenWaypoints += speed / waypoint.endWaypoint;
|
||||
percentBetweenWaypoints = Mathf.Clamp01(percentBetweenWaypoints);
|
||||
easedPercentBetweenWaypoints = Ease(percentBetweenWaypoints);
|
||||
|
||||
nextPos = easedPercentBetweenWaypoints * waypoint.endWaypoint;
|
||||
}else{
|
||||
speed = Time.deltaTime / waypoint.timeBetweenWaypoints * (waypoint.endWaypoint - waypoints[currentCount - 1].endWaypoint);
|
||||
percentBetweenWaypoints += speed / (waypoint.endWaypoint - waypoints[currentCount - 1].endWaypoint);
|
||||
percentBetweenWaypoints = Mathf.Clamp01(percentBetweenWaypoints);
|
||||
easedPercentBetweenWaypoints = Ease(percentBetweenWaypoints);
|
||||
|
||||
nextPos = waypoints[currentCount - 1].endWaypoint + easedPercentBetweenWaypoints * (waypoint.endWaypoint - waypoints[currentCount - 1].endWaypoint);
|
||||
}
|
||||
|
||||
dollyTrackCamera.m_Lens.FieldOfView = Mathf.Lerp(lastFieldOfView, waypoint.fieldOfView, easedPercentBetweenWaypoints);
|
||||
|
||||
if (cameraTrack.m_PathPosition < waypoint.endWaypoint){
|
||||
cameraTrack.m_PathPosition = nextPos;
|
||||
}else{
|
||||
NextWaypoint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float Ease(float x){
|
||||
if (waypoints[currentCount].ease){
|
||||
float a = currentEase + 1;
|
||||
return Mathf.Pow(x, a) / (Mathf.Pow(x, a) + Mathf.Pow(1 - x, a));
|
||||
}else{
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Starts playing the cutscene. </summary>
|
||||
public void StartRail(){
|
||||
paused = false;
|
||||
lastFieldOfView = dollyTrackCamera.m_Lens.FieldOfView;
|
||||
Waypoint waypoint = waypoints[currentCount];
|
||||
if (waypoint.startDelay >= 0)
|
||||
{
|
||||
paused = true;
|
||||
StartCoroutine(DelayMovement(waypoint.startDelay));
|
||||
}
|
||||
currentEase = waypoint.ease ? waypoint.easeAmount : 1;
|
||||
}
|
||||
|
||||
void NextWaypoint(){
|
||||
lastFieldOfView = dollyTrackCamera.m_Lens.FieldOfView;
|
||||
if (currentCount >= totalCount){
|
||||
Debug.Log("Finish");
|
||||
finished = true;
|
||||
|
||||
if (onCutsceneEnd.GetPersistentEventCount() > 0)
|
||||
{
|
||||
onCutsceneEnd.Invoke();
|
||||
}
|
||||
}
|
||||
else{
|
||||
percentBetweenWaypoints = 0;
|
||||
currentCount++;
|
||||
Waypoint waypoint = waypoints[currentCount];
|
||||
if(waypoint.startDelay > 0){
|
||||
paused = true;
|
||||
StartCoroutine(DelayMovement(waypoint.startDelay));
|
||||
}
|
||||
currentEase = waypoint.ease ? waypoint.easeAmount : 1;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator DelayMovement(float delay){
|
||||
yield return new WaitForSeconds(delay);
|
||||
paused = false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6e80df5e5cd6b984396c057f7ce9a9c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,18 @@
|
|||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class Waypoint{
|
||||
|
||||
[Min(0)] public float startDelay;
|
||||
|
||||
[Header("Easing")]
|
||||
public bool ease;
|
||||
[Range(0f, 2f)] public float easeAmount;
|
||||
|
||||
[Header("Waypoints")]
|
||||
[Min(0)] public float timeBetweenWaypoints;
|
||||
[Min(0)] public int endWaypoint;
|
||||
|
||||
[Header("Field of View")]
|
||||
[Range(1, 179)] public float fieldOfView = 60;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cbcbf05409a71c34498aea255a6ba921
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
45
Assets/Scripts/Tools/Cinemachine/ScreenShakeCall.cs
Normal file
45
Assets/Scripts/Tools/Cinemachine/ScreenShakeCall.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
|
||||
public class ScreenShakeCall : MonoBehaviour{
|
||||
|
||||
[SerializeField] bool orbitalCamera = false;
|
||||
CinemachineFreeLook freeLook;
|
||||
CinemachineVirtualCamera vCam;
|
||||
float shakeTimer;
|
||||
float shakeTimerTotal;
|
||||
float startingIntensity;
|
||||
|
||||
public static ScreenShakeCall instance { get; private set; }
|
||||
|
||||
void Awake(){
|
||||
instance = this;
|
||||
vCam = GetComponent<CinemachineVirtualCamera>();
|
||||
freeLook = GetComponent<CinemachineFreeLook>();
|
||||
}
|
||||
|
||||
/// <summary> Smoothly shakes with a certain intensity and duration </summary>
|
||||
public void ShakeCamera(float intensity, float time){
|
||||
startingIntensity = intensity;
|
||||
shakeTimer = shakeTimerTotal = time;
|
||||
}
|
||||
|
||||
void Update(){
|
||||
if (shakeTimer > 0){
|
||||
shakeTimer -= Time.deltaTime;
|
||||
if (orbitalCamera){
|
||||
CinemachineBasicMultiChannelPerlin multiChannelPerlin1 = freeLook.GetRig(0).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
CinemachineBasicMultiChannelPerlin multiChannelPerlin2 = freeLook.GetRig(1).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
CinemachineBasicMultiChannelPerlin multiChannelPerlin3 = freeLook.GetRig(2).GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
multiChannelPerlin1.m_AmplitudeGain = Mathf.Lerp(startingIntensity, 0f, 1 - (shakeTimer / shakeTimerTotal));
|
||||
multiChannelPerlin2.m_AmplitudeGain = Mathf.Lerp(startingIntensity, 0f, 1 - (shakeTimer / shakeTimerTotal));
|
||||
multiChannelPerlin3.m_AmplitudeGain = Mathf.Lerp(startingIntensity, 0f, 1 - (shakeTimer / shakeTimerTotal));
|
||||
}else{
|
||||
CinemachineBasicMultiChannelPerlin multiChannelPerlin = vCam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
|
||||
multiChannelPerlin.m_AmplitudeGain = Mathf.Lerp(startingIntensity, 0f, 1 - (shakeTimer / shakeTimerTotal));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tools/Cinemachine/ScreenShakeCall.cs.meta
Normal file
11
Assets/Scripts/Tools/Cinemachine/ScreenShakeCall.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f000cf598e480f345a7feb226d3b026a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Tools/DialogueSystem.meta
Normal file
8
Assets/Scripts/Tools/DialogueSystem.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f84e53fac975efd4f8bde09ce0339748
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue