Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bc1c644

Browse files
Multiplayer UI
Added the code for the multiplayer UI still need to implement the in game UI so it can be shown to the player
1 parent 6a78ae7 commit bc1c644

File tree

9 files changed

+156
-47
lines changed

9 files changed

+156
-47
lines changed

‎Native_Compilation_Project/Assets/PvP/Scripts/PvP_Health.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Collections;
22
using System.Collections.Generic;
3+
using TMPro;
4+
using Unity.VisualScripting;
35
using UnityEngine;
46
using UnityEngine.InputSystem;
57
using UnityEngine.SceneManagement;
@@ -9,20 +11,25 @@ public class PvP_Health : MonoBehaviour
911
public float maxHealth;
1012
public float currentHealth;
1113

12-
public GameObject SpawnPoint;
14+
public GameObject spawnPoint;
1315
private GameManager gameManager;
1416

1517
public int playerID;
18+
public int deaths;
1619

1720
public void Start()
1821
{
22+
deaths = 0;
1923
currentHealth = maxHealth;
24+
spawnPoint = GameObject.FindGameObjectWithTag("SpawnPoint");
2025
}
2126

2227
public void OnTriggerEnter(Collider collision)
2328
{
2429
if (collision.gameObject.CompareTag("P_DAMAGE"))
2530
{
31+
print(collision.gameObject.GetComponent<INFO>().meleeID);
32+
print(playerID);
2633
if (collision.gameObject.GetComponent<INFO>().meleeID == playerID)
2734
return;
2835
changeHealth(-collision.gameObject.GetComponent<INFO>().damage);
@@ -37,7 +44,8 @@ public void changeHealth(float ammount)
3744
else
3845
{
3946
// respawn the player at the spawn position
40-
transform.position = SpawnPoint.transform.position;
47+
transform.position = spawnPoint.transform.position;
48+
deaths++;
4149
}
4250
}
4351
}

‎Native_Compilation_Project/Assets/PvP/Scripts/PvP_Manager.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

‎Native_Compilation_Project/Assets/PvP/Scripts/PvP_PlayerID.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class PvP_PlayerID : MonoBehaviour
1313
* set the ID on the bullet to be the current player ID
1414
*/
1515
public PvP_PlayerManager manager;
16-
public PvP_Shooting shooting;
1716
public PvP_WeaponManager weaponManager;
1817
public PvP_Health health;
1918

@@ -22,16 +21,18 @@ public void Start()
2221
manager = GameObject.FindGameObjectWithTag("MANAGER").GetComponent<PvP_PlayerManager>();
2322
if (playerID == 1) // Player 1 (blue)
2423
{
25-
shooting = manager.P1.GetComponent<PvP_Shooting>();
2624
weaponManager = manager.P1.GetComponent<PvP_WeaponManager>();
2725
health = manager.P1.GetComponent<PvP_Health>();
2826
// bullet colour
2927
foreach(var item in weaponManager.weapons)
3028
{
31-
item.GetComponent<Shooting>().bullet.GetComponent<MeshRenderer>().material.color = Color.blue;
29+
item.GetComponent<PvP_Shooting>().bullet.GetComponent<MeshRenderer>().sharedMaterial.color = Color.blue;
3230
}
3331
// bullet ID
34-
shooting.bulletID = 0;
32+
foreach (var item in weaponManager.weapons)
33+
{
34+
item.GetComponent<PvP_Shooting>().bulletID = 0;
35+
}
3536
// weapon manager ID
3637
weaponManager.playerID = 0;
3738
// Health ID
@@ -41,22 +42,24 @@ public void Start()
4142
}
4243
else if (playerID == 2) // Player 2 (red)
4344
{
44-
shooting = manager.P1.GetComponent<PvP_Shooting>();
45-
weaponManager = manager.P1.GetComponent<PvP_WeaponManager>();
46-
health = manager.P1.GetComponent<PvP_Health>();
45+
weaponManager = manager.P2.GetComponent<PvP_WeaponManager>();
46+
health = manager.P2.GetComponent<PvP_Health>();
4747
// bullet colour
4848
foreach (var item in weaponManager.weapons)
4949
{
50-
item.GetComponent<Shooting>().bullet.GetComponent<MeshRenderer>().material.color = Color.red;
50+
item.GetComponent<PvP_Shooting>().bullet.GetComponent<MeshRenderer>().sharedMaterial.color = Color.red;
5151
}
5252
// bullet ID
53-
shooting.bulletID = 1;
53+
foreach (var item in weaponManager.weapons)
54+
{
55+
item.GetComponent<PvP_Shooting>().bulletID = 1;
56+
}
5457
// weapon manager ID
5558
weaponManager.playerID = 1;
5659
// Health ID
5760
health.playerID = 1;
5861
// object color
59-
manager.P1.GetComponent<MeshRenderer>().material.color = Color.red;
62+
manager.P2.GetComponent<MeshRenderer>().material.color = Color.red;
6063
}
6164
}
6265
}

‎Native_Compilation_Project/Assets/PvP/Scripts/PvP_PlayerManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void PlayerJoined(PlayerInputManager ctx)
2323
{
2424
var objects = Resources.FindObjectsOfTypeAll(typeof(PvP_Movement));
2525
objects[0].GetComponent<PvP_PlayerID>().playerID = 2;
26-
P1 = objects[0].GameObject();
26+
P2 = objects[0].GameObject();
2727
}
2828

2929
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using JetBrains.Annotations;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using TMPro;
5+
using UnityEngine;
6+
7+
public class PvP_UIManager : MonoBehaviour
8+
{
9+
public PvP_PlayerManager manager;
10+
11+
public TMP_Text P1Kills;
12+
public TMP_Text P1Weapon;
13+
public TMP_Text P1Ammo;
14+
15+
public TMP_Text P2Kills;
16+
public TMP_Text P2Weapon;
17+
public TMP_Text P2cAmmo;
18+
19+
void Start()
20+
{
21+
manager = GameObject.FindGameObjectWithTag("MANAGER").GetComponent<PvP_PlayerManager>();
22+
}
23+
24+
public void updateKillsUI()
25+
{
26+
P1Kills.text = "Kills: " + manager.P2.GetComponent<PvP_Health>().deaths.ToString();
27+
P2Kills.text = "Kills: " + manager.P1.GetComponent<PvP_Health>().deaths.ToString();
28+
}
29+
30+
public void updateP1WeaponsUI()
31+
{
32+
PvP_WeaponManager weaponManager = manager.P1.GetComponent<PvP_WeaponManager>();
33+
if (weaponManager.currentWeapon == 0)
34+
P1Weapon.text = "Pistol";
35+
else if (weaponManager.currentWeapon == 1)
36+
P1Weapon.text = "Shotgun";
37+
else if (weaponManager.currentWeapon == 2)
38+
P1Weapon.text = "Assult Rifle";
39+
P1Ammo.text = weaponManager.weapons[weaponManager.currentWeapon].GetComponent<PvP_Shooting>().curAmmo.ToString() + "/" + weaponManager.weapons[weaponManager.currentWeapon].GetComponent<PvP_Shooting>().curHeldAmmo.ToString();
40+
}
41+
42+
public void updateP2WeaponsUI()
43+
{
44+
PvP_WeaponManager weaponManager = manager.P2.GetComponent<PvP_WeaponManager>();
45+
if (weaponManager.currentWeapon == 0)
46+
P1Weapon.text = "Pistol";
47+
else if (weaponManager.currentWeapon == 1)
48+
P1Weapon.text = "Shotgun";
49+
else if (weaponManager.currentWeapon == 2)
50+
P1Weapon.text = "Assult Rifle";
51+
P1Ammo.text = weaponManager.weapons[weaponManager.currentWeapon].GetComponent<PvP_Shooting>().curAmmo.ToString() + "/" + weaponManager.weapons[weaponManager.currentWeapon].GetComponent<PvP_Shooting>().curHeldAmmo.ToString();
52+
}
53+
}

‎Native_Compilation_Project/Assets/PvP/Scripts/PvP_Manager.cs.meta renamed to ‎Native_Compilation_Project/Assets/PvP/Scripts/PvP_UIManager.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Native_Compilation_Project/Assets/Scenes/PvP.unity

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,37 @@ MeshFilter:
220220
m_PrefabAsset: {fileID: 0}
221221
m_GameObject: {fileID: 18204587}
222222
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
223+
--- !u!1 &69419216
224+
GameObject:
225+
m_ObjectHideFlags: 0
226+
m_CorrespondingSourceObject: {fileID: 0}
227+
m_PrefabInstance: {fileID: 0}
228+
m_PrefabAsset: {fileID: 0}
229+
serializedVersion: 6
230+
m_Component:
231+
- component: {fileID: 69419217}
232+
m_Layer: 0
233+
m_Name: SpawnPoint
234+
m_TagString: SpawnPoint
235+
m_Icon: {fileID: 0}
236+
m_NavMeshLayer: 0
237+
m_StaticEditorFlags: 0
238+
m_IsActive: 1
239+
--- !u!4 &69419217
240+
Transform:
241+
m_ObjectHideFlags: 0
242+
m_CorrespondingSourceObject: {fileID: 0}
243+
m_PrefabInstance: {fileID: 0}
244+
m_PrefabAsset: {fileID: 0}
245+
m_GameObject: {fileID: 69419216}
246+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
247+
m_LocalPosition: {x: 0, y: 0, z: 0}
248+
m_LocalScale: {x: 1, y: 1, z: 1}
249+
m_ConstrainProportionsScale: 0
250+
m_Children: []
251+
m_Father: {fileID: 0}
252+
m_RootOrder: 14
253+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
223254
--- !u!1 &78032624
224255
GameObject:
225256
m_ObjectHideFlags: 0
@@ -585,7 +616,7 @@ RectTransform:
585616
- {fileID: 1975931692}
586617
- {fileID: 1433238309}
587618
m_Father: {fileID: 0}
588-
m_RootOrder: 5
619+
m_RootOrder: 6
589620
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
590621
m_AnchorMin: {x: 0, y: 0}
591622
m_AnchorMax: {x: 0, y: 0}
@@ -1498,7 +1529,7 @@ RectTransform:
14981529
m_Children:
14991530
- {fileID: 223356977}
15001531
m_Father: {fileID: 0}
1501-
m_RootOrder: 3
1532+
m_RootOrder: 4
15021533
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
15031534
m_AnchorMin: {x: 0, y: 0}
15041535
m_AnchorMax: {x: 0, y: 0}
@@ -1774,7 +1805,7 @@ Transform:
17741805
m_ConstrainProportionsScale: 0
17751806
m_Children: []
17761807
m_Father: {fileID: 0}
1777-
m_RootOrder: 12
1808+
m_RootOrder: 13
17781809
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
17791810
--- !u!1 &403246325
17801811
GameObject:
@@ -2005,7 +2036,7 @@ RectTransform:
20052036
m_Children:
20062037
- {fileID: 1506703979}
20072038
m_Father: {fileID: 0}
2008-
m_RootOrder: 8
2039+
m_RootOrder: 9
20092040
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
20102041
m_AnchorMin: {x: 0, y: 0}
20112042
m_AnchorMax: {x: 0, y: 0}
@@ -2479,7 +2510,7 @@ Transform:
24792510
m_PrefabAsset: {fileID: 0}
24802511
m_GameObject: {fileID: 498877919}
24812512
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
2482-
m_LocalPosition: {x: 96.80089, y: -235.12294, z: 207.10165}
2513+
m_LocalPosition: {x: 0, y: 0, z: 0}
24832514
m_LocalScale: {x: 1, y: 1, z: 1}
24842515
m_ConstrainProportionsScale: 0
24852516
m_Children: []
@@ -3350,6 +3381,37 @@ MeshFilter:
33503381
m_PrefabAsset: {fileID: 0}
33513382
m_GameObject: {fileID: 669395437}
33523383
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
3384+
--- !u!1 &670475470
3385+
GameObject:
3386+
m_ObjectHideFlags: 0
3387+
m_CorrespondingSourceObject: {fileID: 0}
3388+
m_PrefabInstance: {fileID: 0}
3389+
m_PrefabAsset: {fileID: 0}
3390+
serializedVersion: 6
3391+
m_Component:
3392+
- component: {fileID: 670475471}
3393+
m_Layer: 0
3394+
m_Name: UI Manager
3395+
m_TagString: Untagged
3396+
m_Icon: {fileID: 0}
3397+
m_NavMeshLayer: 0
3398+
m_StaticEditorFlags: 0
3399+
m_IsActive: 1
3400+
--- !u!4 &670475471
3401+
Transform:
3402+
m_ObjectHideFlags: 0
3403+
m_CorrespondingSourceObject: {fileID: 0}
3404+
m_PrefabInstance: {fileID: 0}
3405+
m_PrefabAsset: {fileID: 0}
3406+
m_GameObject: {fileID: 670475470}
3407+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
3408+
m_LocalPosition: {x: 96.933876, y: -227.12311, z: 179.13232}
3409+
m_LocalScale: {x: 1, y: 1, z: 1}
3410+
m_ConstrainProportionsScale: 0
3411+
m_Children: []
3412+
m_Father: {fileID: 0}
3413+
m_RootOrder: 3
3414+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
33533415
--- !u!1 &699081187
33543416
GameObject:
33553417
m_ObjectHideFlags: 0
@@ -3689,7 +3751,7 @@ Transform:
36893751
m_ConstrainProportionsScale: 0
36903752
m_Children: []
36913753
m_Father: {fileID: 0}
3692-
m_RootOrder: 10
3754+
m_RootOrder: 11
36933755
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
36943756
--- !u!1 &846308591
36953757
GameObject:
@@ -3721,7 +3783,7 @@ Transform:
37213783
m_Children:
37223784
- {fileID: 1367783868}
37233785
m_Father: {fileID: 0}
3724-
m_RootOrder: 11
3786+
m_RootOrder: 12
37253787
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
37263788
--- !u!1 &897056670
37273789
GameObject:
@@ -3817,7 +3879,7 @@ RectTransform:
38173879
m_Children:
38183880
- {fileID: 1839927295}
38193881
m_Father: {fileID: 0}
3820-
m_RootOrder: 7
3882+
m_RootOrder: 8
38213883
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
38223884
m_AnchorMin: {x: 0, y: 0}
38233885
m_AnchorMax: {x: 0, y: 0}
@@ -4107,7 +4169,7 @@ GameObject:
41074169
- component: {fileID: 1054330571}
41084170
- component: {fileID: 1054330570}
41094171
m_Layer: 0
4110-
m_Name: Kills
4172+
m_Name: P2_Kill_Text
41114173
m_TagString: Untagged
41124174
m_Icon: {fileID: 0}
41134175
m_NavMeshLayer: 0
@@ -4410,7 +4472,7 @@ Transform:
44104472
m_ConstrainProportionsScale: 0
44114473
m_Children: []
44124474
m_Father: {fileID: 0}
4413-
m_RootOrder: 9
4475+
m_RootOrder: 10
44144476
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
44154477
--- !u!114 &1154374418
44164478
MonoBehaviour:
@@ -5690,7 +5752,7 @@ RectTransform:
56905752
- {fileID: 1842382305}
56915753
- {fileID: 486176594}
56925754
m_Father: {fileID: 0}
5693-
m_RootOrder: 4
5755+
m_RootOrder: 5
56945756
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
56955757
m_AnchorMin: {x: 0, y: 0}
56965758
m_AnchorMax: {x: 0, y: 0}
@@ -6821,7 +6883,7 @@ RectTransform:
68216883
- {fileID: 1054330569}
68226884
- {fileID: 208110474}
68236885
m_Father: {fileID: 0}
6824-
m_RootOrder: 6
6886+
m_RootOrder: 7
68256887
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
68266888
m_AnchorMin: {x: 0, y: 0}
68276889
m_AnchorMax: {x: 0, y: 0}
@@ -7959,7 +8021,7 @@ GameObject:
79598021
- component: {fileID: 1975931694}
79608022
- component: {fileID: 1975931693}
79618023
m_Layer: 0
7962-
m_Name: Kills
8024+
m_Name: P1_Kill_Text
79638025
m_TagString: Untagged
79648026
m_Icon: {fileID: 0}
79658027
m_NavMeshLayer: 0

‎Native_Compilation_Project/Assets/Weapons/Bullets/Prefabs/Bullet Colour 1.mat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ Material:
134134
- _WorkflowMode: 1
135135
- _ZWrite: 1
136136
m_Colors:
137-
- _BaseColor: {r: 0, g: 0, b: 0, a: 1}
137+
- _BaseColor: {r: 1, g: 0, b: 0, a: 1}
138138
- _CameraFadeParams: {r: 0, g: Infinity, b: 0, a: 0}
139-
- _Color: {r: 0, g: 0, b: 0, a: 1}
139+
- _Color: {r: 0, g: 0, b: 1, a: 1}
140140
- _ColorAddSubDiff: {r: 0, g: 0, b: 0, a: 0}
141141
- _EmissionColor: {r: 128, g: 0, b: 0, a: 1}
142142
- _SoftParticleFadeParams: {r: 0, g: 0, b: 0, a: 0}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /