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); } }
public override IEnumerator ExecuteMelee() { Charge = 0.0f; AttackCharging = false; yield return(new WaitForSeconds(0.6f)); Ray ray; if (playerUW.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)) { //Debug.Log ("you've hit yourself ? " + hit.transform.name); } else { ObjectInteraction objInt = hit.transform.gameObject.GetComponent <ObjectInteraction>(); if (objInt != null) { hit.transform.gameObject.GetComponent <ObjectInteraction>().Attack(10); //Create a blood splatter at this point GameObject hitimpact = new GameObject(hit.transform.name + "_impact"); hitimpact.transform.position = hit.point; //ray.GetPoint(weaponRange/0.7f); Impact imp = hitimpact.AddComponent <Impact>(); imp.FrameNo = objInt.GetHitFrameStart(); imp.EndFrame = objInt.GetHitFrameEnd(); StartCoroutine(imp.Animate()); if (currWeapon != null) { currWeapon.onHit(hit.transform.gameObject); } } else { //do a miss impact GameObject hitimpact = new GameObject(hit.transform.name + "_impact"); hitimpact.transform.position = hit.point; //ray.GetPoint(weaponRange/0.7f); Impact imp = hitimpact.AddComponent <Impact>(); imp.FrameNo = 46; imp.EndFrame = 50; StartCoroutine(imp.Animate()); if (currWeapon != null) { currWeapon.onHit(null); } } } } else { if (currWeapon != null) { currWeapon.onHit(null); } } AttackExecuting = false; }