private void OnTriggerEnter(Collider other) { // handle any damage here! if (!entity.IsOwner) { return; } if (other.tag == Tags.ATTACK_TAG) { if (!other.transform.IsChildOf(transform) && !Hit) // line to not hurt yourself. Also, do not run this code if you have already been hurt. { PlayerController.MajorDamage(); var evnt = SuccessfulAttackEvent.Create(); // successfully attacked! evnt.WeaponDamage = other.transform.parent.parent.parent.GetComponent <WeaponAttack>().Damage; evnt.WeaponEntity = other.transform.parent.parent.parent.GetComponent <BoltEntity>(); evnt.Send(); } } else if (other.tag == Tags.PUSH_TAG) { if (!other.transform.IsChildOf(transform) && !Hit) // line to not hurt yourself. Also, do not run this code if you have already been hurt. { Hit = true; Invoke("ResetHit", StunTime); PlayerController.MinorDamage(); } } else if (other.tag == Tags.SHIELD_TAG) { //print("Got ITEM!!"); var new_Item = ItemPickedUpEvent.Create(); new_Item.PlayerEntity = GetComponent <BoltEntity>(); new_Item.ItemEntity = other.GetComponent <BoltEntity>(); new_Item.Send(); CurrentShield = MaxPlayerShield; if (AudioManager.Instance != null) { AudioManager.Instance.PlaySFX(ShieldGetSFX); } GameUI.UserInterface.InitializeShield(CurrentShield); // add callback here. // run shield here. } else if (other.tag == Tags.WEAPON_TAG && state.Weapon == null) // pick up an item if you have no weapon or trap. { //print("Got ITEM!!"); var new_Item = ItemPickedUpEvent.Create(); new_Item.PlayerEntity = GetComponent <BoltEntity>(); // get the player who picked up the entity. new_Item.ItemEntity = other.GetComponent <BoltEntity>(); // get Itembox for the host to destroy new_Item.ItemType = c_Item_Types.Items[other.GetComponent <Hover>().TypeOfItem]; // get Item ID new_Item.Send(); } else if (other.tag == Tags.DEATHZONE_TAG) { LoseGame(); } }
public override void OnEvent(ItemPickedUpEvent evnt) // all clients and server must understand that the player has oicked up an item. { if (BoltNetwork.IsServer) { if (evnt.ItemEntity != null) { BoltNetwork.Destroy(evnt.ItemEntity); // only the server can spawn item entities } } if (evnt.FromSelf) { if (evnt.ItemType == "" | evnt.ItemType == null) { return; } // return if the item type is a shield or something that is not a weapon/trap. evnt.PlayerEntity.GetComponentInChildren <WeaponManager>().InitializeItem(evnt.ItemType); //BoltNetwork.Instantiate(BoltPrefabs.hammer_low, new Vector3(0,0.2f,0)) } }