Browse Source

Working monsters

main
Joshua Reason 2 years ago
parent
commit
c84aa768e5
4 changed files with 48 additions and 8 deletions
  1. BIN
      Assets/Scenes/MonsterWorking.unity
  2. +7
    -0
      Assets/Scenes/MonsterWorking.unity.meta
  3. +1
    -1
      Assets/Scripts/LevelManager.cs
  4. +37
    -7
      Assets/Scripts/MonsterController.cs

BIN
Assets/Scenes/MonsterWorking.unity (Stored with Git LFS) View File

size 110580

+ 7
- 0
Assets/Scenes/MonsterWorking.unity.meta View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 72869211a51722a49b486c6163795717
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 1
- 1
Assets/Scripts/LevelManager.cs View File

@ -54,7 +54,7 @@ public class LevelManager : MonoBehaviour
private void Start()
{
m_allResetable = FindObjectsOfType<MonoBehaviour>().OfType<IResettable>().ToArray();
m_allResetable = FindObjectsOfType<MonoBehaviour>(true).OfType<IResettable>().ToArray();
m_timer.Value = m_timeInLevel;
m_isVictory.Value = false;

+ 37
- 7
Assets/Scripts/MonsterController.cs View File

@ -14,12 +14,16 @@ public class MonsterController : MonoBehaviour, IResettable
private GameObject[] m_possibleFrames;
[SerializeField]
private Transform m_player;
public GameObject m_defaultObject;
[SerializeField]
private float m_distance = 3;
[SerializeField]
public GameObject m_defaultObject;
private Vector3 m_offset = Vector3.zero;
private bool m_hasChanged = false;
private void OnEnable()
{
@ -33,6 +37,7 @@ public class MonsterController : MonoBehaviour, IResettable
private void Start()
{
m_player = GameObject.FindGameObjectWithTag("Player").transform;
foreach (Transform child in transform)
{
if (child.gameObject.activeInHierarchy)
@ -53,14 +58,35 @@ public class MonsterController : MonoBehaviour, IResettable
}
}
private void ResetMonster()
{
foreach (Transform child in transform)
{
child.gameObject.SetActive(child.gameObject == m_defaultObject);
}
}
private void OnLightChange(float value)
{
if (value <= 0)
float distanceToPlayer = Vector3.Distance(m_player.position, transform.position + m_offset);
if (value <= 0.1 && distanceToPlayer < m_distance && !m_hasChanged)
{
Debug.Log(distanceToPlayer);
ChangeRandomMonster();
m_hasChanged = true;
}
else if (value <= 0)
{
ResetMonster();
}
if (value > 0.5)
{
m_hasChanged = false;
}
}
public void OnLevelLoad()
@ -75,9 +101,13 @@ public class MonsterController : MonoBehaviour, IResettable
public void OnResetEnd()
{
foreach (Transform child in transform)
{
child.gameObject.SetActive(child.gameObject == m_defaultObject);
}
ResetMonster();
}
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(transform.position + m_offset, m_distance);
}
}

Loading…
Cancel
Save