void Awake() { priceText = transform.GetChild(0).Find("PriceText").GetComponent <Text>(); itemNameText = transform.GetChild(0).Find("ItemNameText").GetComponent <Text>(); playerHealth = GameObject.Find("Player").GetComponent <CPlayerHealth>(); itemImage = transform.GetComponentInChildren <SpriteRenderer>(); }
void OnTriggerStay(Collider collider) { if (CNetwork.IsServer) { if (burning) { // Damage everything within radius that is flammable. CActorHealth victimHealth = collider.GetComponent <CActorHealth>(); if (victimHealth != null) { if (victimHealth.flammable) { victimHealth.health -= Time.fixedDeltaTime; } else { // Damage players - they use their own health script. CPlayerHealth otherPlayerhealth = collider.GetComponent <CPlayerHealth>(); if (otherPlayerhealth != null) { otherPlayerhealth.ApplyDamage(Time.fixedDeltaTime); } } } } } }
private void Awake() { animator = GetComponent <Animator>(); rigidBody = GetComponent <Rigidbody2D>(); audioSource = GetComponent <AudioSource>(); health = GetComponent <CPlayerHealth>(); }
void OnCollisionEnter(Collision collision) { if (CNetwork.IsServer) { //Assume player weighs 80 kg float fMass = 80; //Acceleration will be the relative velocity, as this is essentially an instant change in velocity. float fAcceleration = collision.relativeVelocity.magnitude; //f = ma float fNetForce = fMass * fAcceleration; if (fNetForce > m_fForceDamageThreshold) { CPlayerHealth health = gameObject.GetComponent <CPlayerHealth>(); //Make damage scale exponentially, according to force. //For reference, a human punch can exert up to 5000 newtons of force. Let's assume that would hurt lots. float fDamage = Mathf.Log(fNetForce, 2); health.ApplyDamage(Mathf.Clamp(fDamage, 5, 45)); //Debug.Log("Player took damage after being hit by " + collision.gameObject.name); //Debug.Log("Force = " + fNetForce.ToString()); //Debug.Log("Damage = " + fDamage.ToString()); } } }
private void Awake() { SetItemList(); SetAllRewards(); itemName[0].transform.parent.parent.gameObject.SetActive(true); equipGunName[0].transform.parent.parent.gameObject.SetActive(false); nameText = transform.GetComponentsInChildren <Text>(); player = GameObject.Find("Player").GetComponent <CPlayerHealth>(); }
private void UpdateListInformation() { foreach (KeyValuePair <ulong, GameObject> listItem in m_PlayersList) { // Set the alive status CPlayerHealth playerActorHealth = CGamePlayers.GetPlayerActor(listItem.Key).GetComponent <CPlayerHealth>(); if (playerActorHealth.CurrentHealthState == CPlayerHealth.HealthState.ALIVE) { listItem.Value.transform.FindChild("StatusAlive").gameObject.SetActive(true); listItem.Value.transform.FindChild("StatusDead").gameObject.SetActive(false); } else { listItem.Value.transform.FindChild("StatusAlive").gameObject.SetActive(false); listItem.Value.transform.FindChild("StatusDead").gameObject.SetActive(true); } } }
void OnHealthStateChanged(GameObject _SourcePlayer, CPlayerHealth.HealthState _eHealthCurrentState, CPlayerHealth.HealthState _eHealthPreviousState) { switch (_eHealthCurrentState) { case CPlayerHealth.HealthState.DOWNED: { s_cSerializeStream.Write((byte)ENetworkAction.EventDeath); break; } case CPlayerHealth.HealthState.ALIVE: { s_cSerializeStream.Write((byte)ENetworkAction.EventRevive); break; } } }
// Use this for initialization void Awake() { _health = GetComponentInParent <CPlayerHealth>(); _healthImage = GetComponent <Image>(); }
void RespawnPlayer(GameObject _SourcePlayer, CPlayerHealth.HealthState _eHealthCurrentState, CPlayerHealth.HealthState _eHealthPreviousState) { // If the previous health state was DEAD // And current health state is ALIVE if (_eHealthCurrentState == CPlayerHealth.HealthState.DEAD) { // Save a list of currently constructed spawners List<GameObject> aPlayerSpawners = CModuleInterface.FindModulesByType(CModuleInterface.EType.PlayerSpawner); // Iterate through every spawner foreach (GameObject cPlayerSpawner in aPlayerSpawners) { // If the spawner is not blocked if (!cPlayerSpawner.GetComponent<CPlayerSpawnerBehaviour>().IsBlocked) { //Ensure the collider is enabled! _SourcePlayer.rigidbody.collider.enabled = true; // "Board" the ship // Note: Does nothing unless the player 'dies' outside the ship _SourcePlayer.GetComponent<CActorBoardable>().BoardActor(); // Set the player's position and rotation based upon the spawner's position and rotation _SourcePlayer.GetComponent<CNetworkView>().SetPosition(cPlayerSpawner.GetComponent<CPlayerSpawnerBehaviour>().m_cSpawnPosition.transform.position); _SourcePlayer.GetComponent<CNetworkView>().SetRotation(cPlayerSpawner.GetComponent<CPlayerSpawnerBehaviour>().m_cSpawnPosition.transform.rotation); // Heal the player to max health _SourcePlayer.GetComponent<CPlayerHealth>().ApplyHeal(_SourcePlayer.GetComponent<CPlayerHealth>().MaxHealth); // TODO: Reset other variables such as suit atmosphere and equipped tools // Break loop break; } } } }
void Start() { health = GameObject.Find("Player").GetComponent <CPlayerHealth>(); this.name = KDefine.ITEM_SHIELD; }