// Use this for initialization void Start() { Player1 = GameObject.Find("Player1"); Player2 = GameObject.Find("Player2"); x1 = (Healthsystem)Player1.GetComponent("Healthsystem"); x2 = (Healthsystem)Player2.GetComponent("Healthsystem"); }
public void setup(Healthsystem healthsystem) { this.healthsystem = healthsystem; healthsystem.HealthChanged += Healthsystem_HealthChanged; updatehealthbar(); }
private void Start() { Healthsystem healthsystem = new Healthsystem(5); Debug.Log("health: " + healthsystem.GetHealth()); healthsystem.Damage(10); healthsystem.Heal(19); Debug.Log("health: " + healthsystem.GetHealth()); }
void spawnPlayer(Object prefab) { if (Network.isServer) { player1Object = Network.Instantiate(prefab, spawnObject.position, Quaternion.identity, 0); player1Object.name = "Player"; GameObject.Find("Player").layer = LayerMask.NameToLayer("LayerSelf"); changeLayer(GameObject.Find("Player")); player1 = (PlayerController)GameObject.Find("Player").GetComponent("PlayerController"); player1Health = (Healthsystem)GameObject.Find("Player").GetComponent("Healthsystem"); player1Health.playernumber = 1; player1Health.controller1 = player1; player1Health.player1 = player1Health; player1.health = player1Health; camera = (CameraFightScene)GameObject.Find("Main Camera").GetComponent("CameraFightScene"); camera.player1 = GameObject.Find("Player").transform; healthBar = (Healthbar)GameObject.Find("Main Camera").GetComponent("Healthbar"); healthBar.x1 = player1Health; networkView.RPC("changePlayers", RPCMode.AllBuffered, 1); if (playersplaying == 2) { networkView.RPC("player2connect", RPCMode.AllBuffered, true); } } else { if (Network.isClient) { player2Object = Network.Instantiate(prefab, spawnObject2.position, Quaternion.identity, 1); player2Object.name = "Player2"; GameObject.Find("Player2").layer = LayerMask.NameToLayer("LayerSelf"); changeLayer(GameObject.Find("Player2")); player2 = (PlayerController)GameObject.Find("Player2").GetComponent("PlayerController"); player2Health = (Healthsystem)GameObject.Find("Player2").GetComponent("Healthsystem"); player2Health.playernumber = 2; player2Health.controller2 = player2; player2Health.player2 = player2Health; player2.health = player2Health; camera = (CameraFightScene)GameObject.Find("Main Camera").GetComponent("CameraFightScene"); camera.player2 = GameObject.Find("Player2").transform; healthBar = (Healthbar)GameObject.Find("Main Camera").GetComponent("Healthbar"); healthBar.x2 = player2Health; networkView.RPC("changePlayers", RPCMode.AllBuffered, 1); if (playersplaying == 2) { networkView.RPC("player2connect", RPCMode.AllBuffered, true); } } } }
void Start() { if (networkView.isMine) { direction = transform.TransformDirection(Vector3.forward); controller = (CharacterController)GetComponent(typeof(CharacterController)); animation = (Animation)GetComponent(typeof(Animation)); if (!animation) { Debug.Log("The character you would like to control doesn't have animations. Moving her might look weird."); } Spawn(); health = (Healthsystem)GetComponent(typeof(Healthsystem)); } }
// Update is called once per frame void Update() { if (refreshing) { if (MasterServer.PollHostList().Length > 0) { refreshing = false; Debug.Log(MasterServer.PollHostList().Length); hostData = MasterServer.PollHostList(); } } if (Player2connected) { if (Network.isServer) { player2 = (PlayerController)GameObject.Find("Opponent(Clone)").GetComponent("PlayerController"); player2Health = (Healthsystem)GameObject.Find("Opponent(Clone)").GetComponent("Healthsystem"); player1.Opponent = GameObject.Find("Opponent(Clone)").transform; player1.canControl = true; player1Health.controller2 = player2; player1Health.player2 = player2Health; player1Health.Opponentname = player2.name; player2.Opponent = GameObject.Find("Player").transform; player2.canControl = true; player2.health = player2Health; player2Health.playernumber = 2; player2Health.controller1 = player1; player2Health.controller2 = player2; player2Health.player1 = player1Health; player2Health.player2 = player2Health; player2Health.Opponentname = player1.name; changeDamage(GameObject.Find("Opponent(Clone)")); for (int i = 0; i < player1Health.enemy.Length; i++) { player1Health.enemy[i] = player1Health.enemy[i] + "O"; } healthBar.x2 = player2Health; camera.player2 = GameObject.Find("Opponent(Clone)").transform; //networkView.RPC("changePlayers",RPCMode.AllBuffered,-2); } else { player1 = (PlayerController)GameObject.Find("Opponent(Clone)").GetComponent("PlayerController"); player1Health = (Healthsystem)GameObject.Find("Opponent(Clone)").GetComponent("Healthsystem"); player2.Opponent = GameObject.Find("Opponent(Clone)").transform; player2.canControl = true; player2Health.controller1 = player1; player2Health.player1 = player1Health; player1.Opponent = GameObject.Find("Player2").transform; player1.canControl = true; player1.health = player1Health; player1Health.playernumber = 1; player1Health.controller1 = player1; player1Health.controller2 = player2; player1Health.player1 = player1Health; player1Health.player2 = player2Health; changeDamage(GameObject.Find("Opponent(Clone)")); for (int i = 0; i < player2Health.enemy.Length; i++) { player2Health.enemy[i] = player2Health.enemy[i] + "O"; } healthBar.x1 = player1Health; camera.player1 = GameObject.Find("Opponent(Clone)").transform; //networkView.RPC("changePlayers",RPCMode.AllBuffered,-2); } Player2connected = false; } /*if(playersplaying >= -2 && playersplaying<0) * { * if(Network.isServer) * { * networkView.RPC("sendPlayerInfo",RPCMode.AllBuffered,1,playername); * } * else * { * networkView.RPC("sendPlayerInfo",RPCMode.AllBuffered,2,playername); * } * networkView.RPC("changePlayers",RPCMode.AllBuffered,1); * }*/ if (Network.isServer && player1Health != null && player2Health != null && j <= 1) { networkView.RPC("sendPlayerInfo", RPCMode.AllBuffered, 1, playername); j++; } if (Network.isClient && player2Health != null && player1Health != null && j <= 1) { networkView.RPC("sendPlayerInfo", RPCMode.AllBuffered, 2, playername); j++; } DontDestroyOnLoad(thisGameObject); }
// Start is called before the first frame update void Start() { currentHealth = MaxHealth; Healthbar = GetComponent <Image>(); unit = FindObjectOfType <Healthsystem>(); }
private void Start() { anim = GetComponentInChildren <Animator>(); HS = GetComponent <Healthsystem>(); fade = GetComponent <Fade>(); }