Browse Source

4-player support

master
Josh 2 years ago
parent
commit
903a12db3d
  1. 51
      unity_project/Assets/BeatEmUp_GameTemplate3D/01_Game.unity
  2. 8104
      unity_project/Assets/BeatEmUp_GameTemplate3D/Resources/UI.prefab
  3. 5
      unity_project/Assets/BeatEmUp_GameTemplate3D/Scripts/Enemy/EnemyActions.cs
  4. 2
      unity_project/Assets/BeatEmUp_GameTemplate3D/Scripts/Player/PlayerMovement.cs
  5. 3
      unity_project/Assets/BeatEmUp_GameTemplate3D/Scripts/Player/PlayerSpawnPoint.cs
  6. 22
      unity_project/Assets/BeatEmUp_GameTemplate3D/Scripts/UI/UIHUDHealthBar.cs

51
unity_project/Assets/BeatEmUp_GameTemplate3D/01_Game.unity

@ -3449,6 +3449,52 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 666480318}
m_Mesh: {fileID: 4300016, guid: 56a9e5d3ec4e1d045ad05d326d5980ef, type: 3}
--- !u!1 &695471181
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 695471183}
- component: {fileID: 695471182}
m_Layer: 0
m_Name: PlayerSpawnPoint (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &695471182
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 695471181}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 98eda79dab49cfe44b6074347dc5d0bb, type: 3}
m_Name:
m_EditorClassIdentifier:
defaultPlayerPrefab: {fileID: 4829762580851969597, guid: f519f28b6d434bf4c85c400ae1ada1d5,
type: 3}
playerNumber: 1
--- !u!4 &695471183
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 695471181}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 12.6, y: 0.645, z: 0.32}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &701485306 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 461070, guid: 6c925d90c8ae6b148b428e7fe79c3f71,
@ -6083,8 +6129,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 98eda79dab49cfe44b6074347dc5d0bb, type: 3}
m_Name:
m_EditorClassIdentifier:
defaultPlayerPrefab: {fileID: 4829762580851969597, guid: f519f28b6d434bf4c85c400ae1ada1d5,
defaultPlayerPrefab: {fileID: 4829762580851969597, guid: 811341057a44b124d964d1e6963e4957,
type: 3}
playerNumber: 0
--- !u!4 &1339983190
Transform:
m_ObjectHideFlags: 0
@ -6093,7 +6140,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1339983188}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 12.6, y: 0.645, z: -0.667}
m_LocalPosition: {x: 12.6, y: 0.645, z: -2.23}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}

8104
unity_project/Assets/BeatEmUp_GameTemplate3D/Resources/UI.prefab

File diff suppressed because it is too large

5
unity_project/Assets/BeatEmUp_GameTemplate3D/Scripts/Enemy/EnemyActions.cs

@ -117,8 +117,9 @@ public class EnemyActions : MonoBehaviour {
//assign a name to this enemy
if(pickARandomName) enemyName = GetRandomName();
//set player as target
if(target == null) target = GameObject.FindGameObjectWithTag("Player");
//set random player as target
GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
if (target == null) target = players[Random.Range(0, players.Length)];
//tell enemymanager to update the list of active enemies
EnemyManager.getActiveEnemies();

2
unity_project/Assets/BeatEmUp_GameTemplate3D/Scripts/Player/PlayerMovement.cs

@ -42,6 +42,8 @@ public class PlayerMovement : MonoBehaviour {
private float jumpDownwardsForce = .3f;
private float lastJumpTime = 0f;
public int playerNumber;
//a list of states where movement can take place
private List<UNITSTATE> MovementStates = new List<UNITSTATE> {
UNITSTATE.IDLE,

3
unity_project/Assets/BeatEmUp_GameTemplate3D/Scripts/Player/PlayerSpawnPoint.cs

@ -3,6 +3,7 @@
public class PlayerSpawnPoint : MonoBehaviour {
public GameObject defaultPlayerPrefab;
public int playerNumber;
void Awake(){
@ -24,5 +25,7 @@ public class PlayerSpawnPoint : MonoBehaviour {
void loadPlayer(GameObject playerPrefab){
GameObject player = GameObject.Instantiate(playerPrefab) as GameObject;
player.transform.position = transform.position;
player.GetComponent<PlayerMovement>().playerNumber = playerNumber;
}
}

22
unity_project/Assets/BeatEmUp_GameTemplate3D/Scripts/UI/UIHUDHealthBar.cs

@ -8,6 +8,7 @@ public class UIHUDHealthBar : MonoBehaviour {
public Image playerPortrait;
public Slider HpSlider;
public bool isPlayer;
public int playerNumber;
void OnEnable() {
HealthSystem.onHealthChange += UpdateHealth;
@ -23,7 +24,7 @@ public class UIHUDHealthBar : MonoBehaviour {
}
void UpdateHealth(float percentage, GameObject go){
if(isPlayer && go.CompareTag("Player")){
if(isPlayer && go.CompareTag("Player") && go.GetComponent<PlayerMovement>()?.playerNumber == playerNumber){
HpSlider.value = percentage;
}
@ -43,8 +44,17 @@ public class UIHUDHealthBar : MonoBehaviour {
//loads the HUD icon of the player from the player prefab (Healthsystem)
void SetPlayerPortraitAndName(){
if(playerPortrait != null){
GameObject player = GameObject.FindGameObjectWithTag("Player");
HealthSystem healthSystem = player.GetComponent<HealthSystem>();
GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
GameObject player = null;
foreach (GameObject p in players)
{
if (p.GetComponent<PlayerMovement>()?.playerNumber == playerNumber)
player = p;
}
HealthSystem healthSystem = player?.GetComponent<HealthSystem>();
if(player && healthSystem != null){
@ -55,6 +65,12 @@ public class UIHUDHealthBar : MonoBehaviour {
//set name
nameField.text = healthSystem.PlayerName;
}
else
{
nameField.text = "PRESS START!";
playerPortrait.enabled = false;
HpSlider.gameObject.SetActive(false);
}
}
}
}

Loading…
Cancel
Save