303 lines
7.1 KiB
C#
303 lines
7.1 KiB
C#
using System.Collections;
|
||
using System.Timers;
|
||
using UnityEngine;
|
||
|
||
public class FieScript : MonoBehaviour
|
||
{
|
||
[SerializeField] GameObject button;
|
||
|
||
[Header("Spawn Points")]
|
||
|
||
[SerializeField] GameObject SPBack;
|
||
[SerializeField] GameObject SPLeft;
|
||
[SerializeField] GameObject SPRight;
|
||
[SerializeField] GameObject SPDeath;
|
||
|
||
public bool spawnLeft = false;
|
||
public bool spawn2 = false;
|
||
|
||
[Header("Character")]
|
||
|
||
[SerializeField] GameObject Fiefetti;
|
||
//[SerializeField] int damageDealt = 1; //hat aktuell keinen Zweck
|
||
|
||
[SerializeField] public float stateTime = 5f;
|
||
public bool fieKill;
|
||
|
||
[Header("Scripts")]
|
||
|
||
[SerializeField] GameObject scriptPile;
|
||
[SerializeField] GameObject door1; //1 is always Left
|
||
[SerializeField] GameObject door2;
|
||
[SerializeField] GameObject levelScript;
|
||
|
||
[SerializeField] GameObject eSilv;
|
||
[SerializeField] GameObject eHai;
|
||
|
||
[SerializeField] GameObject audioScript;
|
||
|
||
LevelBehavior level;
|
||
ChangeHealth healthScript;
|
||
Door doorSwitch;
|
||
Door doorSwitch2;
|
||
AudioManager audio;
|
||
|
||
SilvScript silv;
|
||
HaiScript hai;
|
||
|
||
private void Awake()
|
||
{
|
||
healthScript = scriptPile.GetComponent<ChangeHealth>();
|
||
doorSwitch = door1.GetComponent<Door>();
|
||
doorSwitch2 = door2.GetComponent<Door>();
|
||
level = levelScript.GetComponent<LevelBehavior>();
|
||
audio = audioScript.GetComponent<AudioManager>();
|
||
|
||
silv = eSilv.GetComponent<SilvScript>();
|
||
hai = eHai.GetComponent<HaiScript>();
|
||
}
|
||
|
||
|
||
void Start()
|
||
{
|
||
button.SetActive(false); //zum vorherigen Debuggen genutzt
|
||
spawnLeft = false;
|
||
|
||
|
||
//StateOne();
|
||
StartStuff();
|
||
}
|
||
|
||
void Update()
|
||
{
|
||
|
||
}
|
||
|
||
public void HitPlayer()
|
||
{
|
||
healthScript.GetHit();
|
||
audio.PlaySFX(audio.fieHit);
|
||
}
|
||
|
||
public void StartStuff()
|
||
{
|
||
Debug.Log("I´m starting stuff.");
|
||
StartCoroutine(WanderAround());
|
||
}
|
||
|
||
IEnumerator WanderAround()
|
||
{
|
||
float elapsed = 0f;
|
||
Debug.Log("Fiefetti: Wandering around");
|
||
|
||
button.SetActive(false);
|
||
|
||
Fiefetti.transform.position = SPBack.transform.position;
|
||
|
||
//Hauptposition
|
||
Debug.Log("Fiefetti: Bin hinten");
|
||
|
||
int random = Random.Range(1, 3);
|
||
if (random == 1) //1 bedeutet immer left
|
||
{
|
||
spawnLeft = true;
|
||
}
|
||
else
|
||
{
|
||
spawnLeft = false;
|
||
}
|
||
Debug.Log("random = " + random);
|
||
|
||
while (elapsed < stateTime)
|
||
{
|
||
elapsed += Time.deltaTime;
|
||
|
||
}
|
||
yield return new WaitForSeconds(stateTime);
|
||
|
||
StartCoroutine(WanderClose());
|
||
}
|
||
|
||
IEnumerator WanderClose()
|
||
{
|
||
|
||
|
||
float elapsed2 = 0;
|
||
|
||
if (spawnLeft == true) //1 bedeutet immer left
|
||
{
|
||
Fiefetti.transform.position = SPLeft.transform.position;
|
||
Debug.Log("Ich stehe links.");
|
||
}
|
||
else
|
||
{
|
||
Fiefetti.transform.position = SPRight.transform.position;
|
||
Debug.Log("Ich stehe rechts.");
|
||
}
|
||
|
||
|
||
//einen von zwei Punkten aussuchen
|
||
Debug.Log("Fiefetti: Komme näher");
|
||
|
||
while (elapsed2 < stateTime)
|
||
{
|
||
elapsed2 += Time.deltaTime;
|
||
|
||
audio.PlaySFX(audio.comingCloser);
|
||
}
|
||
|
||
yield return new WaitForSeconds(stateTime);
|
||
|
||
audio.PlaySFX(audio.scare);
|
||
|
||
StartCoroutine(GetTooClose());
|
||
}
|
||
|
||
IEnumerator GetTooClose()
|
||
{
|
||
float elapsed3 = 0;
|
||
|
||
float stickAround = 0f;
|
||
|
||
if (spawnLeft && doorSwitch.isOpen == true)
|
||
{
|
||
Fiefetti.transform.position = SPDeath.transform.position;
|
||
Debug.Log("Fiefetti: Hab dich!");
|
||
//reingehen
|
||
HitPlayer();
|
||
//StateOne();
|
||
|
||
silv.silvKill = false;
|
||
hai.haiKill = false;
|
||
fieKill = true;
|
||
stickAround += Time.deltaTime;
|
||
if (stickAround >= 2f)
|
||
{
|
||
Fiefetti.transform.position = SPBack.transform.position;
|
||
stickAround = 0f;
|
||
}
|
||
}
|
||
|
||
else if (!spawnLeft && doorSwitch2.isOpen == true)
|
||
{
|
||
Fiefetti.transform.position = SPDeath.transform.position;
|
||
Debug.Log("Fiefetti: Hab dich!");
|
||
//reingehen
|
||
HitPlayer();
|
||
//StateOne();
|
||
|
||
silv.silvKill = false;
|
||
hai.haiKill = false;
|
||
fieKill = true;
|
||
stickAround += Time.deltaTime;
|
||
if (stickAround >= 2f)
|
||
{
|
||
Fiefetti.transform.position = SPBack.transform.position;
|
||
stickAround = 0f;
|
||
}
|
||
}
|
||
|
||
else
|
||
{
|
||
//AudioSpielen
|
||
fieKill = false;
|
||
level.earnedGems += level.earnGems;
|
||
Debug.Log("Du hast bereits " + level.earnedGems + " Gems verdient.");
|
||
Debug.Log("Fiefetti: Och menno");
|
||
Fiefetti.transform.position = SPBack.transform.position;
|
||
audio.PlaySFX(audio.bang);
|
||
}
|
||
|
||
spawnLeft = false;
|
||
//StateOne();
|
||
|
||
while (elapsed3 < stateTime)
|
||
{
|
||
elapsed3 += Time.deltaTime;
|
||
}
|
||
|
||
yield return new WaitForSeconds(stateTime);
|
||
|
||
StartCoroutine(WanderAround());
|
||
}
|
||
|
||
/*
|
||
public void StateOne()
|
||
{
|
||
button.SetActive(false);
|
||
|
||
Fiefetti.transform.position = SPBack.transform.position;
|
||
|
||
//Hauptposition
|
||
Debug.Log("Fiefetti: Bin hinten");
|
||
|
||
int random = Random.Range(1, 3);
|
||
if (random == 1) //1 bedeutet immer left
|
||
{
|
||
spawn1 = true;
|
||
}
|
||
else
|
||
{
|
||
spawn2 = true;
|
||
}
|
||
Debug.Log("random = " + random);
|
||
|
||
//StartCoroutine(WanderClose());
|
||
}*/
|
||
/*
|
||
public void StateTwo()
|
||
{
|
||
if (spawn1 == true) //1 bedeutet immer left
|
||
{
|
||
Fiefetti.transform.position = SPLeft.transform.position;
|
||
}
|
||
else
|
||
{
|
||
Fiefetti.transform.position = SPRight.transform.position;
|
||
}
|
||
|
||
StartCoroutine(WanderAround());
|
||
|
||
//einen von zwei Punkten aussuchen
|
||
Debug.Log("Fiefetti: Komme näher");
|
||
|
||
//StateThree();
|
||
}*/
|
||
/*
|
||
public void StateThree()
|
||
{
|
||
if (doorSwitch.isOpen == true)
|
||
{
|
||
Fiefetti.transform.position = SPDeath.transform.position;
|
||
Debug.Log("Fiefetti: Hab dich!");
|
||
//reingehen
|
||
HitPlayer();
|
||
//StateOne();
|
||
fieKill = true;
|
||
}
|
||
|
||
else if (doorSwitch2.isOpen == true)
|
||
{
|
||
Fiefetti.transform.position = SPDeath.transform.position;
|
||
Debug.Log("Fiefetti: Hab dich!");
|
||
//reingehen
|
||
HitPlayer();
|
||
//StateOne();
|
||
fieKill = true;
|
||
}
|
||
|
||
else
|
||
{
|
||
//AudioSpielen
|
||
fieKill = false;
|
||
|
||
Debug.Log("Fiefetti: Och menno");
|
||
}
|
||
|
||
StartCoroutine(WanderAround());
|
||
spawn1 = false;
|
||
spawn2 = false;
|
||
//StateOne();
|
||
}*/
|
||
}
|