public static bool DamageOnCollide( GameObject target, SpellPrefabManager src, float damage, List <string> ignore = null, GameplayStatics.DamageType type = GameplayStatics.DamageType.Normal) { if (ignore != null) { if (GameplayStatics.ObjHasTag(target, ignore)) { return(false); } } if (src) { if (target != src.GetOwner() && !SpellVerifySameOwnership(target, src.GetOwner())) { GameplayStatics.ApplyDamage(target, damage, type); return(true); } } return(false); }
public override void OnTick(GameObject obj) { var manager = obj.GetComponent <SpellPrefabManager>(); if (!manager.m_Target) { Destroy(obj); return; } GameplayStatics.ApplyDamage(manager.m_Target, m_Damage, GameplayStatics.DamageType.Fire); }
public override GameObject CastSpell(GameObject owner, GameObject target = null, Vector3?spawn_pos = null, Quaternion?spawn_rot = null) { if (m_Prefab && owner) { Vector3 dir = ((Quaternion)spawn_rot * Vector3.right).normalized; Vector3 rot_dir = ((Quaternion)spawn_rot * Vector3.up).normalized; Quaternion rot = GameplayStatics.GetRotationFromDir(rot_dir); Vector3 target_pos = owner.transform.position + dir * 8.5f; Vector3 spawn_position = spawn_pos != null ? (Vector3)spawn_pos : owner.transform.position; float distance = (spawn_position - target_pos).magnitude; Debug.DrawRay(spawn_position, dir * distance, Color.green, 1.0f); RaycastHit2D[] hit = Physics2D.CircleCastAll(spawn_position, 2.0f, dir, distance, layerMask: GameplayStatics.LayerEnemy); foreach (RaycastHit2D enemy in hit) { GameplayStatics.ApplyDamage(enemy.collider.gameObject, m_Damage); } hit = Physics2D.CircleCastAll(spawn_position, 2.0f, dir, distance, layerMask: LayerMask.GetMask("FlyingEnemy"));; foreach (RaycastHit2D enemy in hit) { GameplayStatics.ApplyDamage(enemy.collider.gameObject, m_Damage); } GameObject obj = Instantiate(m_Prefab); obj.GetComponent <SpellPrefabManager>().SetOwner(owner); obj.tag = "SpellUninteractive"; Destroy(obj.GetComponent <BoxCollider2D>()); obj.transform.position = spawn_position + dir * distance / 2; obj.transform.rotation = rot; obj.transform.localScale = new Vector2(1.5f, distance); // GameplayStatics.AddQuad(obj, m_Material); if (m_Material) { obj.GetComponent <MeshRenderer>().material = m_Material; obj.GetComponent <SpellPrefabManager>().AddOnUpdate((objt) => { SpellPrefabManager spm = objt.GetComponent <SpellPrefabManager>(); objt.GetComponent <MeshRenderer>().material.SetFloat("_Strength", spm.m_TimeToLive - spm.m_TimeAlive); }); } obj.GetComponent <SpellPrefabManager>().m_TimeToLive = m_SpellDuration; obj.GetComponent <SpellPrefabManager>().AddTriggerTick(this.SpellTriggerTick); obj.GetComponent <SpellPrefabManager>().AddOnUpdate(this.OnTick); } return(null); }
private void OnTriggerEnter2D(Collider2D other) { List <string> tags_to_ignore = new List <string>() { "Untagged", "Room", "SpellUninteractive", "Item" }; if (other.CompareTag("SpellInteractive")) { GameObject owner = other.gameObject.GetComponent <SpellPrefabManager>().GetOwner(); if (owner == GetInstantiator()) { return; } } if (GameplayStatics.ObjHasTag(other.gameObject, tags_to_ignore, true) && !GetInstantiator().CompareTag(other.gameObject.tag)) { GameplayStatics.ApplyDamage(other.gameObject, 10); Destroy(gameObject); } }
private void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("SpellInteractive")) { var owner = other.gameObject.GetComponent <SpellPrefabManager>().GetOwner(); if (owner == GetInstantiator()) { return; } } if (ShouldCollide(other)) { GameplayStatics.ApplyDamage(other.gameObject, 10); Destroy(gameObject); } //if (targetTag.Equals("All")) //{ //if (other.CompareTag("Player")|| other.CompareTag("Enemy") || other.CompareTag("DestructibleObject") || (other.CompareTag("SpellInteractive") && !GetInstantiator().CompareTag("Player"))) //{ // other.gameObject.GetComponent<StatusComponent>().TakeDamage(10); // Destroy(gameObject); //} else if (other.CompareTag("Wall") || other.CompareTag("Door") || other.CompareTag("Rock")) //{ // Destroy(gameObject); //} //} //else // if (other.CompareTag("SpellInteractive") || other.CompareTag(targetTag) || other.CompareTag("Wall") || other.CompareTag("Door") || other.CompareTag("DestructibleObject") || other.CompareTag("Rock")) //{ // List<string> tags_to_ignore = new List<string>() { "Untagged", "Room", "" }; // if (other.CompareTag(targetTag) || other.CompareTag("DestructibleObject") || (other.CompareTag("SpellInteractive") && !GetInstantiator().CompareTag("Player"))) // { // other.gameObject.GetComponent<StatusComponent>().TakeDamage(10); // } // Destroy(gameObject); //} }