Added the ability to add multiple players

This commit is contained in:
Anthony Berg 2020-11-24 21:11:44 +00:00
parent 60cb1c814a
commit 9cb342dd42
7 changed files with 78 additions and 68 deletions

View File

@ -3,7 +3,6 @@
<component name="ContentModelUserStore"> <component name="ContentModelUserStore">
<attachedFolders /> <attachedFolders />
<explicitIncludes> <explicitIncludes>
<Path>Assets</Path>
<Path>Library/PackageCache/com.unity.collab-proxy@1.3.9</Path> <Path>Library/PackageCache/com.unity.collab-proxy@1.3.9</Path>
<Path>Library/PackageCache/com.unity.ext.nunit@1.0.0</Path> <Path>Library/PackageCache/com.unity.ext.nunit@1.0.0</Path>
<Path>Library/PackageCache/com.unity.ide.rider@1.2.1</Path> <Path>Library/PackageCache/com.unity.ide.rider@1.2.1</Path>

View File

@ -135,7 +135,7 @@ GameObject:
- component: {fileID: 239567296} - component: {fileID: 239567296}
- component: {fileID: 239567295} - component: {fileID: 239567295}
m_Layer: 5 m_Layer: 5
m_Name: Text (TMP) m_Name: Players Text
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@ -974,7 +974,7 @@ MonoBehaviour:
m_OnClick: m_OnClick:
m_PersistentCalls: m_PersistentCalls:
m_Calls: m_Calls:
- m_Target: {fileID: 1824002928} - m_Target: {fileID: 0}
m_TargetAssemblyTypeName: m_TargetAssemblyTypeName:
m_MethodName: LoadLevel m_MethodName: LoadLevel
m_Mode: 5 m_Mode: 5
@ -1569,6 +1569,7 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 820348872} - component: {fileID: 820348872}
- component: {fileID: 820348873}
m_Layer: 5 m_Layer: 5
m_Name: Play m_Name: Play
m_TagString: Untagged m_TagString: Untagged
@ -1598,6 +1599,22 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &820348873
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 820348871}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 89cbcb58c8de8f14baaea829e70e2cb7, type: 3}
m_Name:
m_EditorClassIdentifier:
playersInput: {fileID: 1814574228}
play: {fileID: 2129375864}
loadingScreen: {fileID: 821978300}
slider: {fileID: 952453483}
--- !u!1 &821978300 --- !u!1 &821978300
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -3010,7 +3027,7 @@ GameObject:
- component: {fileID: 1814574229} - component: {fileID: 1814574229}
- component: {fileID: 1814574228} - component: {fileID: 1814574228}
m_Layer: 5 m_Layer: 5
m_Name: InputField (TMP) m_Name: Players Input
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@ -3180,7 +3197,6 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 1824002929} - component: {fileID: 1824002929}
- component: {fileID: 1824002928}
m_Layer: 0 m_Layer: 0
m_Name: LoadLevel m_Name: LoadLevel
m_TagString: Untagged m_TagString: Untagged
@ -3188,21 +3204,6 @@ GameObject:
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 1
--- !u!114 &1824002928
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1824002927}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 89cbcb58c8de8f14baaea829e70e2cb7, type: 3}
m_Name:
m_EditorClassIdentifier:
playersInput: {fileID: 0}
loadingScreen: {fileID: 821978300}
slider: {fileID: 952453483}
--- !u!4 &1824002929 --- !u!4 &1824002929
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -3806,7 +3807,6 @@ GameObject:
- component: {fileID: 2129375866} - component: {fileID: 2129375866}
- component: {fileID: 2129375865} - component: {fileID: 2129375865}
- component: {fileID: 2129375864} - component: {fileID: 2129375864}
- component: {fileID: 2129375867}
m_Layer: 5 m_Layer: 5
m_Name: PlayButton m_Name: PlayButton
m_TagString: Untagged m_TagString: Untagged
@ -3915,21 +3915,6 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2129375862} m_GameObject: {fileID: 2129375862}
m_CullTransparentMesh: 0 m_CullTransparentMesh: 0
--- !u!114 &2129375867
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2129375862}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 89cbcb58c8de8f14baaea829e70e2cb7, type: 3}
m_Name:
m_EditorClassIdentifier:
playersInput: {fileID: 0}
loadingScreen: {fileID: 0}
slider: {fileID: 0}
--- !u!1 &2143598660 --- !u!1 &2143598660
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -358,11 +358,9 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 4.4997625, y: 10.148768, z: -4.430161} m_LocalPosition: {x: 4.4997625, y: 10.148768, z: -4.430161}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children: []
- {fileID: 1272828669}
- {fileID: 305116344}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 5 m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &85078179 --- !u!1 &85078179
GameObject: GameObject:
@ -1041,7 +1039,7 @@ GameObject:
- component: {fileID: 305116342} - component: {fileID: 305116342}
- component: {fileID: 305116341} - component: {fileID: 305116341}
m_Layer: 0 m_Layer: 0
m_Name: Player2 m_Name: PlayerTemplate
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@ -1117,11 +1115,11 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 305116340} m_GameObject: {fileID: 305116340}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.15476274, y: 0.051231384, z: 0.043160915} m_LocalPosition: {x: 4.345, y: 10.2, z: -4.387}
m_LocalScale: {x: 0.25, y: 0.25, z: 0.25} m_LocalScale: {x: 0.25, y: 0.25, z: 0.25}
m_Children: [] m_Children: []
m_Father: {fileID: 61794250} m_Father: {fileID: 0}
m_RootOrder: 1 m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &310476693 --- !u!1 &310476693
GameObject: GameObject:
@ -1222,7 +1220,7 @@ RectTransform:
- {fileID: 929752267} - {fileID: 929752267}
- {fileID: 653887086} - {fileID: 653887086}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 6 m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0}
@ -4160,7 +4158,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 8 m_RootOrder: 10
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &810784022 --- !u!1 &810784022
GameObject: GameObject:
@ -5233,7 +5231,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 7 m_RootOrder: 9
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &983314467 --- !u!114 &983314467
MonoBehaviour: MonoBehaviour:
@ -5247,6 +5245,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: ede8e3ed967bcfe42886d342fcf3d755, type: 3} m_Script: {fileID: 11500000, guid: ede8e3ed967bcfe42886d342fcf3d755, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
playerParentGameObject: {fileID: 61794249}
playersGameObjects: []
playerTemplate: {fileID: 305116340}
--- !u!114 &983314468 --- !u!114 &983314468
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -5303,9 +5304,7 @@ MonoBehaviour:
- {fileID: 399889870} - {fileID: 399889870}
- {fileID: 724284469} - {fileID: 724284469}
- {fileID: 1679278720} - {fileID: 1679278720}
players: players: []
- {fileID: 1272828665}
- {fileID: 305116340}
currentPlayer: 0 currentPlayer: 0
speed: 10 speed: 10
--- !u!1 &985089322 --- !u!1 &985089322
@ -7109,7 +7108,7 @@ GameObject:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 0
--- !u!65 &1272828666 --- !u!65 &1272828666
BoxCollider: BoxCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -7180,11 +7179,11 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1272828665} m_GameObject: {fileID: 1272828665}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.15476274, y: 0.051231384, z: 0.043160915} m_LocalPosition: {x: 4.345, y: 10.2, z: -4.387}
m_LocalScale: {x: 0.25, y: 0.25, z: 0.25} m_LocalScale: {x: 0.25, y: 0.25, z: 0.25}
m_Children: [] m_Children: []
m_Father: {fileID: 61794250} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1316371467 --- !u!1 &1316371467
GameObject: GameObject:

View File

@ -1,7 +1,4 @@
using System.Collections; public static class GameSettings
using System.Collections.Generic;
public static class GameSettings
{ {
public static int players; public static int players = 2;
} }

View File

@ -1,4 +1,5 @@
using System.Collections; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
@ -10,13 +11,21 @@ public class LevelLoader : MonoBehaviour
{ {
public TMP_InputField playersInput; //This is for how many players the user has selected. public TMP_InputField playersInput; //This is for how many players the user has selected.
public Button play; //This is for the play button.
public GameObject loadingScreen; //Gets the loading screen public GameObject loadingScreen; //Gets the loading screen
public Slider slider; //Gets the slider public Slider slider; //Gets the slider
public void LoadLevel (string sceneName) void Start()
{
play.onClick.AddListener(LoadLevel);
}
public void LoadLevel()
{ {
StartCoroutine(UpdateTable()); //Starts the LoadAsynchronously function StartCoroutine(UpdateTable()); //Starts the LoadAsynchronously function
StartCoroutine(LoadAsynchronously(sceneName)); //Starts the LoadAsynchronously function GameSettings.players = Convert.ToInt32(playersInput.text); //This sets the amount of players that has been set to play in the game.
Debug.Log(GameSettings.players);
StartCoroutine(LoadAsynchronously("monopoly")); //Starts the LoadAsynchronously function
} }
IEnumerator UpdateTable() IEnumerator UpdateTable()

View File

@ -427,6 +427,7 @@ public class Board //Creating the class for the board mechanics.
} }
players[location.Item1].Pay(Convert.ToInt32(property.property_cost)); //This then makes the player pay for the house that they bought. players[location.Item1].Pay(Convert.ToInt32(property.property_cost)); //This then makes the player pay for the house that they bought.
textHandler.UpdateMoney(players[location.Item1].money); //Updates the money on the UI.
} }
public void SellHouseOnProperty(string propertyName) //This function links the UI button and this class to sell properties. public void SellHouseOnProperty(string propertyName) //This function links the UI button and this class to sell properties.
@ -449,6 +450,7 @@ public class Board //Creating the class for the board mechanics.
} }
players[location.Item1].Pay(Convert.ToInt32(property.property_cost)/-2); //This then gives back the money to the player for half the house/hotel's cost. players[location.Item1].Pay(Convert.ToInt32(property.property_cost)/-2); //This then gives back the money to the player for half the house/hotel's cost.
textHandler.UpdateMoney(players[location.Item1].money); //Updates the money on the UI.
} }
private bool BuyHouse() //This function is used to buy houses locally. private bool BuyHouse() //This function is used to buy houses locally.
@ -789,6 +791,7 @@ public class Player
if (ownedProperties[currentProperty].mortgageProperty()) //Mortgages the property and if done successfully.. if (ownedProperties[currentProperty].mortgageProperty()) //Mortgages the property and if done successfully..
{ {
Pay(ownedProperties[currentProperty].property_value / -2); //Gives the user 50% of what the property is worth. (/-2 makes it positive in the Pay function) Pay(ownedProperties[currentProperty].property_value / -2); //Gives the user 50% of what the property is worth. (/-2 makes it positive in the Pay function)
textHandler.UpdateMoney(money); //Updates the money on the UI.
return true; //Says that mortgaging has been done successfully. return true; //Says that mortgaging has been done successfully.
} }
@ -805,6 +808,7 @@ public class Player
if (ownedProperties[currentProperty].unmortgageProperty()) //Unmortgages the property and if done successfully.. if (ownedProperties[currentProperty].unmortgageProperty()) //Unmortgages the property and if done successfully..
{ {
Pay((ownedProperties[currentProperty].property_value / 2) * 1.1f); //Makes the user pay what they got in mortgage plus a 10% interest Pay((ownedProperties[currentProperty].property_value / 2) * 1.1f); //Makes the user pay what they got in mortgage plus a 10% interest
textHandler.UpdateMoney(money); //Updates the money on the UI.
return true; //Says that mortgaging has been done successfully. return true; //Says that mortgaging has been done successfully.
} }
@ -856,12 +860,27 @@ public class Main : MonoBehaviour
//Player variables //Player variables
public List<Player> players = new List<Player>(); //Creates a list for all the players playing in the game. public List<Player> players = new List<Player>(); //Creates a list for all the players playing in the game.
public GameObject playerParentGameObject; //This is where the parent for the player GameObjects goes.
public List<GameObject> playersGameObjects; //This is the list of player GameObjects
public GameObject playerTemplate; //This is the template for each new player created.
private void Awake() private void Awake()
{ {
//Adds the players to the game //Adds the players to the game
players.Add(new Player("smyalygames", 0, GameObject.Find("/Players/Player1")));
players.Add(new Player("coomer", 1, GameObject.Find("/Players/Player2"))); for (int i = 0; i < GameSettings.players; i++)
Debug.Log(players[0].name); //This is just checking if the player has been assigned. {
//Duplicates the player template
//Moves the new player into a parent for players
//Names the game object player and a unique number
Instantiate(playerTemplate, playerTemplate.transform.position, Quaternion.identity, playerParentGameObject.transform).name = $"Player{i}";
playersGameObjects.Add(GameObject.Find($"/Players/Player{i}")); //Adds to a list of GameObjects by searching for the GameObject.
players.Add(new Player($"Player {i}", i, playersGameObjects[i])); //Creates a unique player class for that specific GameObject
}
Destroy(playerTemplate); //Deletes the player template GameObject.
Debug.Log(players[1].name); //This is just checking if the player has been assigned.
existingProperties = JsonConvert.DeserializeObject<List<Property>>(FileHandler.LoadProperties()); //This loads via JSON all the properties from a file which was originally downloaded from a server. existingProperties = JsonConvert.DeserializeObject<List<Property>>(FileHandler.LoadProperties()); //This loads via JSON all the properties from a file which was originally downloaded from a server.
existingCards = JsonConvert.DeserializeObject<List<Cards>>(FileHandler.LoadCards()); //This loads via JSON all the cards from a file which was originally downloaded from a server. existingCards = JsonConvert.DeserializeObject<List<Cards>>(FileHandler.LoadCards()); //This loads via JSON all the cards from a file which was originally downloaded from a server.
board = new Board(players, existingProperties, existingCards); //Creates the board class. board = new Board(players, existingProperties, existingCards); //Creates the board class.

View File

@ -1,4 +1,5 @@
using UnityEngine; using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour public class Movement : MonoBehaviour
{ {
@ -6,7 +7,7 @@ public class Movement : MonoBehaviour
public bool movement = false; public bool movement = false;
private int position = 0; private int position = 0;
public GameObject[] waypoints; public GameObject[] waypoints;
public GameObject[] players; public List<GameObject> players;
public int currentPlayer; public int currentPlayer;
float rotSpeed; float rotSpeed;
public float speed; public float speed;
@ -36,6 +37,7 @@ public class Movement : MonoBehaviour
void Awake() void Awake()
{ {
main = FindObjectOfType<Main>(); main = FindObjectOfType<Main>();
players = main.playersGameObjects;
} }
void Update() void Update()