/* * void Update(){ * * if (Input.GetKeyDown(KeyCode.S)) { * MessagingManager.Broadcast(Messages.RESTART,this.gameObject); * } * * } */ public void Message(Messages message, GameObject sender) { switch (message) { case Messages.RESTART: player0Data = PlayerInfoPasser.GetInfo(0); player1Data = PlayerInfoPasser.GetInfo(1); if (playerA != null) { if (playerA.GetComponent <PlayerInfo>().State == PlayerInfo.PlayerState.ALIVE) { Object.Destroy(playerA); } } if (playerB != null) { if (playerB.GetComponent <PlayerInfo>().State == PlayerInfo.PlayerState.ALIVE) { Object.Destroy(playerB); } } Object.Destroy(healthA); Object.Destroy(healthB); CreatePlayers(); break; } }
// Use this for initialization protected override void Start() { base.Start(); ControllerSetup(); Debug.Log("Controller Setup Passed"); UpdateHighlighting(); PlayerInfoPasser.SetControllers(controllers); Debug.Log("Controller Data Passed"); }
// Use this for initialization void Start() { player0Data = PlayerInfoPasser.GetInfo(0); player1Data = PlayerInfoPasser.GetInfo(1); //Debug.Log(PlayerInfoPasser.GetController(0).movement.array[0]); CreatePlayers(); MessagingManager.AddListener(this); }
void Start() { foreach (Image i in player1ScoreList) { i.color = new Color(i.color.r, i.color.g, i.color.b, 30f / 255f); } foreach (Image i in player2ScoreList) { i.color = new Color(i.color.r, i.color.g, i.color.b, 30f / 255f); } LeftRight = gameObject.AddComponent <AnalogToAxisLayer> (); LeftRightAlt = gameObject.AddComponent <AnalogToAxisLayer> (); LeftRight.axisName = PlayerInfoPasser.GetController(0).movement.x.axisName; LeftRightAlt.axisName = PlayerInfoPasser.GetController(1).movement.x.axisName; victory1Image.color = Color.clear; victory2Image.color = Color.clear; MessagingManager.AddListener(this); }
public override void Submit() { switch (state) { case 2: if (player == 0) { Debug.Log("Player 1 done"); player1.characterID = character.state; player1.weaponID = weapon.state; player1.stats = character.currentStats + weapon.currentStats; player1.characterIcon = characterPortraits[character.state]; weapon.SetState(0); character.SetState(0); statbars.UpdateValues(character.currentStats + weapon.currentStats); player = 1; SetState(0); } else if (player == 1) { player2.characterID = character.state; player2.weaponID = weapon.state; player2.stats = character.currentStats + weapon.currentStats; player2.characterIcon = characterPortraits[character.state]; PlayerInfoPasser.PassInfo(player1, player2); Debug.Log(player1); Debug.Log(player2); int rnd = RNG.Next(minLevelIndex, maxLevelIndex); Application.LoadLevel(rnd); } break; case 3: overlord.SetState(0); break; } }
void CreatePlayers() { Debug.Log("A"); //get info from player data GameObject playerPrefab = characterPrefabs[player0Data.characterID]; GameObject weaponPrefab = weaponPrefabs[player0Data.weaponID]; //instantiate player prefab in random position from 0,0 Vector3 pos = new Vector3(RNG.NextFloat(-1, 2), 0, RNG.NextFloat(-1, 2)).normalized *RNG.NextFloat(minSpawnDistance, maxSpawnDistance); while (NavMesh.SamplePosition(pos, out _hit, 0.4f, NavMesh.AllAreas) == false) { pos = new Vector3(RNG.NextFloat(-1, 2), 0, RNG.NextFloat(-1, 2)).normalized *RNG.NextFloat(minSpawnDistance, maxSpawnDistance); Debug.Log("CantSpawnA"); } playerA = (GameObject)GameObject.Instantiate( playerPrefab, pos, Quaternion.identity); cameraReference.a = playerA.GetComponentInChildren <RigidBodyTopDownMovement>().gameObject; playerA.GetComponent <PlayerInfo> ().controller = PlayerInfoPasser.GetController(0); playerA.GetComponent <PlayerInfo>().AssignPlayer(0); //instantiate weapon prefab GameObject weaponA = (GameObject)GameObject.Instantiate(weaponPrefab, pos, Quaternion.identity); playerA.GetComponent <PlayerInfo>().AttachWeapon(weaponA); //weaponA.GetComponent<AttachWeapon>().Attach(playerA, playerA.GetComponent<PlayerInfo>().rightRotator); //set up HUD Debug.Log(canvas + " HealthA " + healthA); healthA = (GameObject)GameObject.Instantiate(healthBarPrefab, new Vector3(960, -768, 0), Quaternion.identity); Debug.Log(canvas + " HealthA " + healthA + " SECOND"); healthA.transform.SetParent(canvas.transform, false); healthA.GetComponent <HealthBar>().SetIcon(player0Data.characterIcon); playerA.GetComponentInChildren <ReceiveDamageOnCollision>().healthBar = healthA.GetComponent <HealthBar>(); playerA.GetComponentInChildren <ReceiveDamageOnCollision>().health = 100 * player0Data.stats.health; playerA.GetComponentInChildren <RigidBodyTopDownMovement>().speedMultiplier = 1 + player0Data.stats.speed; Debug.Log("B"); playerPrefab = characterPrefabs[player1Data.characterID]; weaponPrefab = weaponPrefabs[player1Data.weaponID]; Vector3 posB = new Vector3(RNG.NextFloat(-1, 2), 0, RNG.NextFloat(-1, 2)).normalized *RNG.NextFloat(minSpawnDistance, maxSpawnDistance); while (Vector3.Magnitude(pos - posB) < 8) { posB = new Vector3(RNG.NextFloat(-1, 2), 0, RNG.NextFloat(-1, 2)).normalized *RNG.NextFloat(minSpawnDistance, maxSpawnDistance); while (NavMesh.SamplePosition(posB, out _hit, 0.4f, NavMesh.AllAreas) == false) { posB = new Vector3(RNG.NextFloat(-1, 2), 0, RNG.NextFloat(-1, 2)).normalized *RNG.NextFloat(minSpawnDistance, maxSpawnDistance); Debug.Log("CantspawnB"); } } playerB = (GameObject)GameObject.Instantiate( playerPrefab, posB, Quaternion.identity); cameraReference.b = playerB.GetComponentInChildren <RigidBodyTopDownMovement>().gameObject; playerB.GetComponent <PlayerInfo> ().controller = PlayerInfoPasser.GetController(1); playerB.GetComponent <PlayerInfo>().AssignPlayer(1); GameObject weaponB = (GameObject)GameObject.Instantiate(weaponPrefab, posB, Quaternion.identity); //weaponB.transform.Rotate(0, 0, 90); playerB.GetComponent <PlayerInfo>().AttachWeapon(weaponB); //weaponB.GetComponent<AttachWeapon>().Attach(playerB, playerB.GetComponent<PlayerInfo>().rightRotator); healthB = (GameObject)GameObject.Instantiate(healthBarPrefab, new Vector3(960, -768, 0), Quaternion.identity); healthB.transform.SetParent(canvas.transform, false); healthB.GetComponent <RectTransform>().localScale = new Vector3(-1, 1, 1); healthB.GetComponent <HealthBar>().SetIcon(player1Data.characterIcon); playerB.GetComponentInChildren <ReceiveDamageOnCollision>().healthBar = healthB.GetComponent <HealthBar>(); playerB.GetComponentInChildren <ReceiveDamageOnCollision>().health = 100 * player1Data.stats.health; playerB.GetComponentInChildren <RigidBodyTopDownMovement>().speedMultiplier = 1 + player1Data.stats.speed; Debug.Log("Done"); }