Catacombs - add minion spwaner
This commit is contained in:
parent
b85ae59b7f
commit
d64d8cd1a7
File diff suppressed because it is too large
Load Diff
8
Assets/Scripts/REFACTORING/Application/Tools.meta
Normal file
8
Assets/Scripts/REFACTORING/Application/Tools.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ecd9a913f89a143409823e2fe877bb1b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
109
Assets/Scripts/REFACTORING/Application/Tools/CounterRespowner.cs
Normal file
109
Assets/Scripts/REFACTORING/Application/Tools/CounterRespowner.cs
Normal file
@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
class CounterRespowner : MonoBehaviour
|
||||
{
|
||||
public const string RESPOWNER_NAME = "DungeonRespowner";
|
||||
|
||||
public bool Respown = true;
|
||||
|
||||
public int Counter = 20;
|
||||
|
||||
public List<GameObject> minions;
|
||||
|
||||
public List<GameObject> respownPoints;
|
||||
|
||||
public int killedMinions = 0;
|
||||
|
||||
private IEnumerator coroutine;
|
||||
|
||||
|
||||
public void Start()
|
||||
{
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if(Respown && Counter > 0)
|
||||
{
|
||||
Respown = false;
|
||||
|
||||
if (killedMinions < 4 && Counter > 20)
|
||||
{
|
||||
coroutine = SpownWithDelay(1.5f);
|
||||
} else if(Counter <= 20 && killedMinions >= 4)
|
||||
{
|
||||
coroutine = SpownWithDelay(3.0f);
|
||||
}
|
||||
|
||||
StartCoroutine(coroutine);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// najpier 10
|
||||
// a potem w wiekszych dstepach kolejne 20
|
||||
private IEnumerator SpownWithDelay(float waitTime)
|
||||
{
|
||||
yield return new WaitForSeconds(waitTime);
|
||||
|
||||
RespownMinion();
|
||||
|
||||
Counter -= 1;
|
||||
Respown = true;
|
||||
}
|
||||
|
||||
public void RespownMinion()
|
||||
{
|
||||
GameObject minion = null;
|
||||
Vector3 spowner = Vector3.zero;
|
||||
|
||||
// Draw minion
|
||||
minion = minions
|
||||
.ElementAt(UnityEngine.Random.Range(0, minions.Count()))
|
||||
;
|
||||
|
||||
// Decide which spowner use
|
||||
spowner = respownPoints
|
||||
.ElementAt(UnityEngine.Random.Range(0, respownPoints.Count()))
|
||||
.transform
|
||||
.position
|
||||
;
|
||||
|
||||
// Change position
|
||||
var newPosition = new Vector3(
|
||||
spowner.x + UnityEngine.Random.Range(-3.8f, 3.8f),
|
||||
spowner.y + UnityEngine.Random.Range(-3.8f, 3.8f),
|
||||
10
|
||||
);
|
||||
|
||||
BuildMinion(minion, newPosition);
|
||||
}
|
||||
|
||||
public void BuildMinion(GameObject minion, Vector3 coord)
|
||||
{
|
||||
var sceneGui = GameObject.FindGameObjectWithTag("EnemyCollection");
|
||||
|
||||
if (sceneGui == null)
|
||||
{
|
||||
throw new Exception("GUI not found on scene!!!");
|
||||
return;
|
||||
}
|
||||
|
||||
var newMinion = GameObject.Instantiate(minion, coord, Quaternion.identity, sceneGui.transform);
|
||||
|
||||
newMinion.name = minion.name;
|
||||
// newMinion.transform.SetParent(sceneGui.transform);
|
||||
|
||||
newMinion.GetComponent<SpriteRenderer>().sortingOrder = 3;
|
||||
|
||||
newMinion.AddComponent<RespownTrigger>();
|
||||
newMinion.GetComponent<RespownTrigger>().SetParentRespowner(gameObject);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b61fe647fb4fe9409164deb62d90214
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(FollowingEnemy))]
|
||||
class RespownTrigger : MonoBehaviour
|
||||
{
|
||||
public GameObject CoreRespowner;
|
||||
|
||||
public bool wasKilled = false;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if(gameObject.GetComponent<FollowingEnemy>().isKilled == 1 && !wasKilled)
|
||||
{
|
||||
wasKilled = true;
|
||||
|
||||
MarkAsKilled();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetParentRespowner(GameObject parentRespowner)
|
||||
{
|
||||
CoreRespowner = parentRespowner;
|
||||
}
|
||||
|
||||
public void MarkAsKilled()
|
||||
{
|
||||
CoreRespowner.GetComponent<CounterRespowner>().killedMinions += 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4f603d596528c449baa28b55f2e3e5e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6a6280a851ff4c4f8474126e0b12b73
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user