Komplett Lauffähig + Vibration + Boni + Enemie "Jumpscares" - Audio
This commit is contained in:
210
Assets/Scripts/Enemy/SilvScript.cs
Normal file
210
Assets/Scripts/Enemy/SilvScript.cs
Normal file
@@ -0,0 +1,210 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class SilvScript : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] GameObject button;
|
||||
|
||||
[Header("Spawn Points")]
|
||||
|
||||
[SerializeField] GameObject SPBack;
|
||||
[SerializeField] GameObject SPLeft;
|
||||
[SerializeField] GameObject SPRight;
|
||||
[SerializeField] GameObject SPDeath;
|
||||
|
||||
bool spawnLeft = false;
|
||||
|
||||
[Header("Character")]
|
||||
|
||||
[SerializeField] GameObject Silv;
|
||||
//[SerializeField] int damageDealt = 1; //hat aktuell keinen Zweck
|
||||
|
||||
[SerializeField] public float stateTime = 15f;
|
||||
public bool silvKill;
|
||||
|
||||
[Header("Scripts")]
|
||||
|
||||
[SerializeField] GameObject scriptPile;
|
||||
[SerializeField] GameObject door1; //1 is always Left
|
||||
[SerializeField] GameObject door2;
|
||||
[SerializeField] GameObject levelScript;
|
||||
|
||||
[SerializeField] GameObject eFie;
|
||||
[SerializeField] GameObject eHai;
|
||||
|
||||
LevelBehavior level;
|
||||
ChangeHealth healthScript;
|
||||
Door doorSwitch;
|
||||
Door doorSwitch2;
|
||||
|
||||
FieScript fie;
|
||||
HaiScript hai;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
level = levelScript.GetComponent<LevelBehavior>();
|
||||
healthScript = scriptPile.GetComponent<ChangeHealth>();
|
||||
doorSwitch = door1.GetComponent<Door>();
|
||||
doorSwitch2 = door2.GetComponent<Door>();
|
||||
|
||||
fie = eFie.GetComponent<FieScript>();
|
||||
hai = eHai.GetComponent<HaiScript>();
|
||||
}
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
button.SetActive(false); //zum vorherigen Debuggen genutzt
|
||||
spawnLeft = false;
|
||||
|
||||
|
||||
//StateOne();
|
||||
StartStuff();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void HitPlayer()
|
||||
{
|
||||
healthScript.GetHit();
|
||||
}
|
||||
|
||||
public void StartStuff()
|
||||
{
|
||||
Debug.Log("I´m starting stuff.");
|
||||
StartCoroutine(WanderAround());
|
||||
}
|
||||
|
||||
IEnumerator WanderAround()
|
||||
{
|
||||
float elapsed = 0;
|
||||
|
||||
Debug.Log("Silv: Wandering around");
|
||||
|
||||
button.SetActive(false);
|
||||
|
||||
Silv.transform.position = SPBack.transform.position;
|
||||
|
||||
//Hauptposition
|
||||
Debug.Log("Silv: 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
|
||||
{
|
||||
Silv.transform.position = SPLeft.transform.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
Silv.transform.position = SPRight.transform.position;
|
||||
}
|
||||
|
||||
//einen von zwei Punkten aussuchen
|
||||
Debug.Log("Silv: Komme näher");
|
||||
|
||||
while (elapsed2 < stateTime)
|
||||
{
|
||||
elapsed2 += Time.deltaTime;
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(stateTime);
|
||||
|
||||
StartCoroutine(GetTooClose());
|
||||
}
|
||||
|
||||
IEnumerator GetTooClose()
|
||||
{
|
||||
float elapsed3 = 0;
|
||||
|
||||
float stickAround = 0f;
|
||||
|
||||
if (spawnLeft && doorSwitch.isOpen == true)
|
||||
{
|
||||
Silv.transform.position = SPDeath.transform.position;
|
||||
Debug.Log("Silv: Hab dich!");
|
||||
//reingehen
|
||||
HitPlayer();
|
||||
//StateOne();
|
||||
|
||||
fie.fieKill = false;
|
||||
hai.haiKill = false;
|
||||
silvKill = true;
|
||||
|
||||
stickAround += Time.deltaTime;
|
||||
if (stickAround >= 2f)
|
||||
{
|
||||
Silv.transform.position = SPBack.transform.position;
|
||||
stickAround = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
else if (!spawnLeft && doorSwitch2.isOpen == true)
|
||||
{
|
||||
Silv.transform.position = SPDeath.transform.position;
|
||||
Debug.Log("Silv: Hab dich!");
|
||||
//reingehen
|
||||
HitPlayer();
|
||||
//StateOne();
|
||||
|
||||
fie.fieKill = false;
|
||||
hai.haiKill = false;
|
||||
silvKill = true;
|
||||
|
||||
stickAround += Time.deltaTime;
|
||||
if (stickAround >= 2f)
|
||||
{
|
||||
Silv.transform.position = SPBack.transform.position;
|
||||
stickAround = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
//AudioSpielen
|
||||
silvKill = false;
|
||||
level.earnedGems += level.earnGems;
|
||||
Debug.Log("Silv: Och menno");
|
||||
Silv.transform.position = SPBack.transform.position;
|
||||
}
|
||||
|
||||
spawnLeft = false;
|
||||
//StateOne();
|
||||
|
||||
while (elapsed3 < stateTime)
|
||||
{
|
||||
elapsed3 += Time.deltaTime;
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(stateTime);
|
||||
|
||||
StartCoroutine(WanderAround());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user