Skip to content

Commit

Permalink
Merge pull request #19 from Game-Shenanigans/fix-null-pointer
Browse files Browse the repository at this point in the history
Fixed a couple errors
  • Loading branch information
gphorvath authored Jun 30, 2023
2 parents cc9ef82 + 094e05b commit 160c8f2
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 40 deletions.
9 changes: 9 additions & 0 deletions Assets/Prefabs/MenuCanvas.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ GameObject:
- component: {fileID: 2750418062797237111}
- component: {fileID: 2750418062797237112}
- component: {fileID: 2750418062797237113}
- component: {fileID: 1477994944203990988}
m_Layer: 5
m_Name: MenuCanvas
m_TagString: Untagged
Expand Down Expand Up @@ -452,3 +453,11 @@ MonoBehaviour:
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!81 &1477994944203990988
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2750418062797237114}
m_Enabled: 1
2 changes: 1 addition & 1 deletion Assets/Prefabs/Player.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5fd42fff9a6a0044d8da1295c8ccb199, type: 3}
m_Name:
m_EditorClassIdentifier:
maxHealth: 100
maxHealth: 30
currentHealth: 0
--- !u!50 &3184054842604669707
Rigidbody2D:
Expand Down
4 changes: 2 additions & 2 deletions Assets/Prefabs/Zombie.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5fd42fff9a6a0044d8da1295c8ccb199, type: 3}
m_Name:
m_EditorClassIdentifier:
maxHealth: 100
maxHealth: 30
currentHealth: 0
--- !u!114 &8303843776451715842
MonoBehaviour:
Expand All @@ -67,7 +67,7 @@ MonoBehaviour:
<wanderRadius>k__BackingField: 5
<alertDistance>k__BackingField: 11
<damage>k__BackingField: 10
<attackRange>k__BackingField: 1.25
<attackRange>k__BackingField: 1.3
<attackCooldown>k__BackingField: 1
--- !u!50 &3184054842604669707
Rigidbody2D:
Expand Down
2 changes: 1 addition & 1 deletion Assets/Prefabs/ZombieSpawner.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
enemyPrefab: {fileID: 1507955574594264855, guid: 906e9ae527c1e1a4fa792bc6e89757bd, type: 3}
<spawnInterval>k__BackingField: 3.5
<spawnInterval>k__BackingField: 3
<maxSpawns>k__BackingField: 0
--- !u!212 &1746166374861614841
SpriteRenderer:
Expand Down
9 changes: 0 additions & 9 deletions Assets/Scenes/DeathScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -4015,22 +4015,13 @@ GameObject:
m_Component:
- component: {fileID: 373886647}
- component: {fileID: 373886646}
- component: {fileID: 373886645}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &373886645
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 373886644}
m_Enabled: 1
--- !u!20 &373886646
Camera:
m_ObjectHideFlags: 0
Expand Down
9 changes: 0 additions & 9 deletions Assets/Scenes/LifeScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -190,22 +190,13 @@ GameObject:
m_Component:
- component: {fileID: 373886647}
- component: {fileID: 373886646}
- component: {fileID: 373886645}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &373886645
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 373886644}
m_Enabled: 1
--- !u!20 &373886646
Camera:
m_ObjectHideFlags: 0
Expand Down
9 changes: 0 additions & 9 deletions Assets/Scenes/StartMenu.unity
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,13 @@ GameObject:
m_Component:
- component: {fileID: 373886647}
- component: {fileID: 373886646}
- component: {fileID: 373886645}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &373886645
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 373886644}
m_Enabled: 1
--- !u!20 &373886646
Camera:
m_ObjectHideFlags: 0
Expand Down
20 changes: 12 additions & 8 deletions Assets/Scripts/Control/EnemyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private IEnumerator Idle()
state = State.Chase;
directlyAlerted = true;
}
else if (IsChasingEnemyNearby())
else if (IsChasingEnemyNearby() && target != null)
state = State.Chase;
else
state = State.Wander;
Expand Down Expand Up @@ -108,8 +108,9 @@ private IEnumerator Wander()
Vector3 targetPosition = transform.position + wanderDirection * wanderRadius;
transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);

if (target != null && Vector3.Distance(target.position, transform.position) < chaseDistance)
state = State.Chase;
if (target != null)
if (Vector3.Distance(target.position, transform.position) < chaseDistance)
state = State.Chase;

yield return null;
}
Expand All @@ -123,6 +124,13 @@ private IEnumerator Chase()
{
transform.position = Vector3.MoveTowards(transform.position, target.position, speed * Time.deltaTime);

if (Vector3.Distance(target.position, transform.position) > chaseDistance)
{
state = State.Wander;
directlyAlerted = false; // Reset the flag when the enemy stops chasing
yield return null;
}

if (Vector3.Distance(target.position, transform.position) <= chaseDistance)
{
directlyAlerted = true;
Expand All @@ -135,11 +143,7 @@ private IEnumerator Chase()
}
}

if (Vector3.Distance(target.position, transform.position) > chaseDistance)
{
state = State.Wander;
directlyAlerted = false; // Reset the flag when the enemy stops chasing
}

}
AlertNearbyEnemies();

Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/Stats/Health.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ private void Die()
OnDeath?.Invoke();

// Destroy the game object
Destroy(gameObject);
//Destroy(gameObject);
gameObject.SetActive(false);
}

public float GetCurrentHealth()
Expand Down

0 comments on commit 160c8f2

Please sign in to comment.