public int TryDestroyHazard(PlayerID player) { if (player == hazardOwner) { return(-1); } bool generatePowerUp = UnityEngine.Random.Range(0f, 1f) > 0.95f; int powerUp = UnityEngine.Random.Range(0, powerUps.Count); if (DataUtility.gameData.isNetworkedGame) { PunTools.PhotonRPC(view, "RPC_TryDestroyHazard", RpcTarget.AllBuffered, player, generatePowerUp, powerUp); return(HazardLevel); } else { if (generatePowerUp) { Instantiate(powerUps[powerUp], transform.position, Quaternion.identity); } gameObject.SetActive(false); spawner.HazardDestroyed(HazardLevel, transform.position, player, this); spawner.Return(this); return(HazardLevel); } }
public void Initialize(HazardSpawner hazardSpawner, int level, Vector3 pos, PlayerID owner = PlayerID.NP, float dir = 1) { spawner = hazardSpawner; if (DataUtility.gameData.isNetworkedGame) { PunTools.PhotonRpcMine(view, "RPC_Initialize", RpcTarget.AllBuffered, level, pos, owner, dir); } else { gameObject.SetActive(true); transform.localScale = level * scaleFactor * Vector3.one; transform.position = pos; xSpeed = speed * dir; ySpeed = gravity; HazardLevel = level; alive = true; hazardOwner = owner; thrown = false; throwSpeed = Vector3.zero; GetComponent <Renderer>().material.color = DataUtility.GetColorFor(owner); } }
public void Throw(bool left, PlayerID owner) { if (DataUtility.gameData.isNetworkedGame) { PunTools.PhotonRPC(view, "RPC_ThrowHazard", RpcTarget.AllBuffered, left, owner, transform.position); } else { ThrowInternal(left, owner, transform.position); } }
public void DestroyHazard() { if (DataUtility.gameData.isNetworkedGame) { PunTools.PhotonRPC(view, "RPC_DestroyHazard", RpcTarget.AllBuffered); } else { spawner.Return(this); } }
private void ShootProjectile() { if (DataUtility.gameData.isNetworkedGame) { PunTools.PhotonRpcMine(photonView, "RPC_ShootProjectile", RpcTarget.AllBuffered); } else { InternalShootProjectile(); } }
public void Damage(float amount) { if (!invulnerable) { if (DataUtility.gameData.isNetworkedGame) { PunTools.PhotonRpcMine(photonView, "RPC_Damage", RpcTarget.AllBuffered, amount); } else { health -= amount; OnUIShouldUpdate?.Invoke(); invulnerable = true; SetColor(DataUtility.gameData.PlayerInvColor); system.emissionRate = 0; Invoke("SwitchOfInv", 2.0f); SoundManager.Instance.PlaySound(damageClip); } } }
void Update() { if (!isLocal || !initialized) { return; } if (!m_MoveAction.enabled) { return; } // Movement var move = m_MoveAction.ReadValue <Vector2>(); if (_charaterController.isGrounded && move.y > 0.4f) { _moveDirection.y = jumpSpeed; animator.SetTrigger("jump"); } _moveDirection.y -= gravity * Time.deltaTime; _moveDirection.x = moveSpeed * move.x; _charaterController.Move(_moveDirection * Time.deltaTime); if (Mathf.Abs(_moveDirection.x) > 1) { animator.SetBool("forward", (m_otherPlayer.transform.position.x - transform.position.x) * _moveDirection.x > 0 ? true : false); animator.SetBool("backwards", (m_otherPlayer.transform.position.x - transform.position.x) * _moveDirection.x > 0 ? false : true); } else { animator.SetBool("forward", false); animator.SetBool("backwards", false); } // Fire if (m_FireAction.triggered && throwHazard != null) { throwHazard.Throw(transform.forward.x > 0 ? false : true, playerID); } else if (m_FireAction.triggered && _charaterController.isGrounded) { if (_currentShot == null || !_currentShot.alive) { animator.SetTrigger("shoot"); ShootProjectile(); } else if (instantShoot) { animator.SetTrigger("shoot"); ShootProjectile(); } } if (m_SuperAction.triggered && super >= 100f) { super = 0f; OnUIShouldUpdate?.Invoke(); if (DataUtility.gameData.isNetworkedGame) { PunTools.PhotonRpcMine(photonView, "RPC_Super", RpcTarget.MasterClient); } else { DoSuperInteral(); } } transform.position = new Vector3(transform.position.x, transform.position.y, 0f); if (m_otherPlayer != null) { transform.forward = new Vector3((m_otherPlayer.transform.position.x - transform.position.x) > 0 ? 1 : -1, 0, 0); } }