void Update() { if (player.Dead) { return; } if (syncPropertyAgent.GetPropertyWithName(SHOOTING).GetBoolValue()) { currentGun.Fire(); } if (networkID.IsMine) { if (Input.GetKeyUp(KeyCode.Alpha1)) { syncPropertyAgent.Modify(CURRENT_WEAPON_INDEX, (int)Constants.Guns.Laser); //ActivateWeapon(Constants.Guns.Laser); } else if (Input.GetKeyUp(KeyCode.Alpha2)) { syncPropertyAgent.Modify(CURRENT_WEAPON_INDEX, (int)Constants.Guns.MachineGun); //ActivateWeapon(Constants.Guns.MachineGun); } bool shooting = Input.GetButton("Fire1"); if (shooting != lastShootingState) { syncPropertyAgent.Modify(SHOOTING, shooting); lastShootingState = shooting; } } }
public void OnHPReady() { Debug.Log("OnHPPropertyReady"); // Get the current value of the "hp" SyncProperty. currentHP = syncPropertyAgent.GetPropertyWithName("hp").GetIntValue(); // Check if the local player has ownership of the GameObject. // Source GameObject can modify the "hp" SyncProperty. // Remote duplicates should only be able to read the "hp" SyncProperty. if (networkId.IsMine) { int version = syncPropertyAgent.GetPropertyWithName("hp").version; if (version != 0) { // You can check the version of a SyncProperty to see if it has been initialized. // If version is not 0, it means the SyncProperty has been modified before. // Probably the player got disconnected from the game. // Set hpSlider's value to currentHP to restore player's hp. hpSlider.value = currentHP; } else { // If version is 0, you can call the Modify() method on the SyncPropertyAgent to initialize player's hp to maxHp. syncPropertyAgent.Modify("hp", maxHp); hpSlider.value = maxHp; } } else { hpSlider.value = currentHP; } }
public void OnHealthReady() { int version = syncPropertyAgent.GetPropertyWithName(HEALTH).version; if (version == 0) { syncPropertyAgent.Modify(HEALTH, MaxHp); } }
public void TakeDamage(int damage) { int health = syncPropertyAgent.GetPropertyWithName(HEALTH).GetIntValue(); health = Mathf.Clamp(health - damage, 0, MaxHealth); if (NetworkClient.Instance == null || NetworkClient.Instance.IsHost) { syncPropertyAgent.Modify(HEALTH, health); } }
public void OnHealthSyncPropertyReady() { int health = syncPropertyAgent.GetPropertyWithName(HEALTH).GetIntValue(); int version = syncPropertyAgent.GetPropertyWithName(HEALTH).version; if (version == 0) { syncPropertyAgent.Modify(HEALTH, MaxHealth); health = MaxHealth; } UpdateHealthBar(health); }
public void ChangeTurn() { int currentTurn = syncAgent.GetPropertyWithName("Turn").GetIntValue(); if (currentTurn == 1) { syncAgent.Modify(TURN, 2); } else { syncAgent.Modify(TURN, 1); } Debug.Log("turn online vala hai : " + syncAgent.GetPropertyWithName("Turn").GetIntValue()); // Debug.Log("abhi baari iski hai: "+currentTurn); }
// Update is called once per frame void Update() { if (Input.GetKeyUp(KeyCode.Space) && networkID.IsMine) { int modelCount = models.Count; int modelIndex = syncPropertyAgent.GetPropertyWithName(MODEL_INDEX).GetIntValue(); if (modelCount == 0 || modelCount == 1) { return; } else if (modelIndex < models.Count - 1) { syncPropertyAgent.Modify(MODEL_INDEX, modelIndex + 1); } else { syncPropertyAgent.Modify(MODEL_INDEX, 0); } } }