public string caster; //who has cast the project. It will ignore them. void OnCollisionEnter(Collision collision) { if (collision.gameObject.name == caster) { return; } if (HasHit == true) { //Only impact once. return; } else { HasHit = true; SpriteRenderer sprt = this.GetComponentInChildren <SpriteRenderer>(); sprt.enabled = false; BoxCollider box = this.GetComponent <BoxCollider>(); box.enabled = false; WindowDetect.FreezeMovement(this.gameObject); ObjectInteraction objInt = collision.gameObject.GetComponent <ObjectInteraction>(); if (objInt != null) { objInt.Attack(damage); Impact imp = this.gameObject.AddComponent <Impact>(); imp.FrameNo = objInt.GetHitFrameStart(); imp.EndFrame = objInt.GetHitFrameEnd(); StartCoroutine(imp.Animate()); } else { //test if this is a player. if (collision.gameObject.GetComponent <UWCharacter>() != null) { collision.gameObject.GetComponent <UWCharacter>().ApplyDamage(damage); } else { //do a miss impact Impact imp = this.gameObject.AddComponent <Impact>(); imp.FrameNo = 46; imp.EndFrame = 50; StartCoroutine(imp.Animate()); } } DestroyObject(this.gameObject, 1); } }
protected virtual void Detonate(Collision collision) { HasHit = true; //Code to execute when a projectile hits a spot (for launching AOE effects) spellprop.onImpact(this.transform); ObjectInteraction objInt = collision.gameObject.GetComponent <ObjectInteraction> (); if (objInt != null) //Has the projectile hit anything { //Special code for magic spell direct hits. spellprop.onHit(objInt); //Applies damage objInt.Attack(spellprop.BaseDamage, caster); //Create a impact animation to illustrate the collision if (objInt.GetHitFrameStart() >= 0) { Impact.SpawnHitImpact(Impact.ImpactMagic(), objInt.GetImpactPoint(), objInt.GetHitFrameStart(), objInt.GetHitFrameEnd()); } } else { //Test if this is a player. if (collision.gameObject.GetComponent <UWCharacter> () != null) { int ratio = UWCharacter.Instance.getSpellResistance(spellprop); collision.gameObject.GetComponent <UWCharacter> ().ApplyDamage(spellprop.BaseDamage / ratio); spellprop.onHitPlayer(); } else { //Do a miss impact Impact.SpawnHitImpact(Impact.ImpactDamage(), this.transform.position, spellprop.impactFrameStart, spellprop.impactFrameEnd); } } DestroyProjectile(); }
/// <summary> /// The Projectile hits something. /// </summary> /// <param name="collision">Collision.</param> /// Does not impact the caster /// Calls onImpact /// Calls onHit /// Applys Attack /// Generates an impact effect void OnCollisionEnter(Collision collision) { // if (caster == null) { caster = this.gameObject; } if (collision.gameObject.name == caster.name) { //Prevents the caster from hitting themselves return; } if (HasHit == true) { //Only impact once. return; } else { HasHit = true; //Code to execute when a projectile hits a spot (for launching AOE effects) spellprop.onImpact(this.transform); ObjectInteraction objInt = collision.gameObject.GetComponent <ObjectInteraction>(); if (objInt != null) //Has the projectile hit anything { //Special code for magic spell direct hits. spellprop.onHit(objInt); //Applies damage objInt.Attack(spellprop.BaseDamage, caster); //Create a impact animation to illustrate the collision if (objInt.GetHitFrameStart() >= 0) { Impact.SpawnHitImpact(Impact.ImpactMagic(), objInt.GetImpactPoint(), objInt.GetHitFrameStart(), objInt.GetHitFrameEnd()); } } else { //Test if this is a player. if (collision.gameObject.GetComponent <UWCharacter>() != null) { collision.gameObject.GetComponent <UWCharacter>().ApplyDamage(spellprop.BaseDamage); spellprop.onHitPlayer(); } else { //Do a miss impact Impact.SpawnHitImpact(Impact.ImpactDamage(), this.transform.position, spellprop.impactFrameStart, spellprop.impactFrameEnd); } } ObjectInteraction objIntThis = this.GetComponent <ObjectInteraction>(); if (objIntThis != null) { objIntThis.objectloaderinfo.InUseFlag = 0; //Free up object slot } DestroyObject(this.gameObject); } }
/// <summary> /// Executes the melee attack after the attack has been released. /// Casts a ray from the centre of the screen in mouselook mode or from the cursor position /// Waits a period of time after the release before casting the ray. /// </summary> public override IEnumerator ExecuteMelee(string StrikeType, float StrikeCharge) { yield return(new WaitForSeconds(0.4f)); Ray ray; if (UWCharacter.Instance.MouseLookEnabled == true) { ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f)); } else { ray = Camera.main.ScreenPointToRay(Input.mousePosition); } RaycastHit hit = new RaycastHit(); if (Physics.Raycast(ray, out hit, weaponRange)) { if (!hit.transform.Equals(this.transform)) { ObjectInteraction objInt = hit.transform.gameObject.GetComponent <ObjectInteraction>(); if (objInt != null) { //Debug.Log("Hitting " + objInt.name); switch (objInt.GetItemType()) { case ObjectInteraction.NPC_TYPE: PC_Hits_NPC(UWCharacter.Instance, currWeapon, CurrentStrike, StrikeCharge, objInt.GetComponent <NPC>(), hit); break; default: Impact.SpawnHitImpact(Impact.ImpactDamage(), (ray.origin + hit.point) / 2f, DamageImpactStart, DamageImpactEnd); objInt.Attack((short)GetPlayerBaseDamage(currWeapon, CurrentStrike), UWCharacter.Instance.gameObject); break; } } else {//Probably hit a wall or tile floor Impact.SpawnHitImpact(Impact.ImpactDamage(), (ray.origin + hit.point) / 2f, DamageImpactStart, DamageImpactEnd); if (currWeapon != null) { short durability = currWeapon.getDurability(); if (durability <= 30) { currWeapon.SelfDamage((short)(Mathf.Max(0, Random.Range(1, durability + 1) - durability))); } } if (ObjectInteraction.PlaySoundEffects) { UWCharacter.Instance.aud.clip = MusicController.instance.SoundEffects[MusicController.SOUND_EFFECT_MELEE_MISS_1]; UWCharacter.Instance.aud.Play(); } } } } else { if (ObjectInteraction.PlaySoundEffects) { UWCharacter.Instance.aud.clip = MusicController.instance.SoundEffects[MusicController.SOUND_EFFECT_MELEE_MISS_1]; UWCharacter.Instance.aud.Play(); } if (currWeapon != null) { currWeapon.onHit(null); } } ///Ends the attack and wait for a period before allowing another action. AttackExecuting = false; UWHUD.instance.window.UWWindowWait(1.0f); }