|
|
@ -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); |
|
|
|
} |
|
|
|
} |