Search Unity

Resolved Strange Collider trigger on a specific layer

Discussion in 'Physics' started by Pierre-Marie, Jan 23, 2023.

  1. Pierre-Marie

    Pierre-Marie

    Joined:
    Aug 3, 2015
    Posts:
    52
    Hi,

    I tried to detect if an enemy is in the range of action of a spell to make it as a target so I can outline it.

    I have an enemy in my scene with a attached gameObject with a collider not set to trigger.
    The layer of this gameobject is "SpellColliderLayer".
    upload_2023-1-23_11-43-44.png

    I also have two spell gameobject.
    Both set up with a colldier set as trigger and a rigid Body attached in the "SpellColliderLayer.

    In the Projet settings / physics I enables all contact pair and the "SpellColliderLayer" interact only with himself :
    upload_2023-1-23_11-39-33.png

    Basicly the setup should Be fine but only On of the spell detect the enemy.

    This one correctly trigger Enter and Exit with the Enemy :
    upload_2023-1-23_11-40-46.png

    Code (CSharp):
    1. using Assets._01_script.CardsScripts;
    2. using Assets._04_ScriptableObjects;
    3. using MoreMountains.Feedbacks;
    4. using MoreMountains.TopDownEngine;
    5. using System.Collections;
    6. using System.Collections.Generic;
    7. using TowerDefense.Assets.script;
    8. using UnityEngine;
    9. using UnityEngine.Rendering;
    10. using UnityEngine.UIElements;
    11. using static AutoCasterSccript;
    12. using static Broccoli.Utils.LSystem;
    13. using static SelectedCardScript;
    14.  
    15. public class SelfExplosion : MonoBehaviour, ISpell
    16. {
    17.     [SerializeField] PlayerScript playerScript;
    18.     [SerializeField] private MMF_Player feedbakcPlayer;
    19.  
    20.     //Spell configuration
    21.     [SerializeField] private float minIntensity;
    22.     [SerializeField] private float maxIntensity;
    23.     [SerializeField] private float magicalRatio;
    24.     [SerializeField] private float physicalRatio;
    25.     [SerializeField] private float cost;
    26.  
    27.     [SerializeField] private bool CastOnSelect;
    28.     [SerializeField] private bool isOver;
    29.     [SerializeField] private bool isSelected;
    30.     [SerializeField] private float Expliosionradius;
    31.     [SerializeField] private float LastExpliosionradius;
    32.     [SerializeField] private float ExpliosionDamageMin;
    33.     [SerializeField] private float ExpliosionDamageMax;
    34.     [SerializeField] private GameObject sphere;
    35.     [SerializeField] private MeshRenderer SphereRender;
    36.     [SerializeField] public AutoCasterSccript autoCaster;
    37.     private SphereCollider sphereColldier;
    38.    
    39.  
    40.     private HashSet<GameObject> EnemyWhitinCollider = new HashSet<GameObject>();
    41.  
    42.     [SerializeField] private bool activateOutline = false;
    43.    
    44.     private void Start()
    45.     {
    46.         Expliosionradius = (float)(2.5 * (playerScript.playerEntityData.PowerMagic / 100));
    47.         ExpliosionDamageMin = (int)(2 * (playerScript.playerEntityData.PowerMagic / 100));
    48.         ExpliosionDamageMax = (int)(3 * (playerScript.playerEntityData.PowerMagic / 100));
    49.         LastExpliosionradius = Expliosionradius;
    50.         sphere.transform.localScale = new Vector3(2*Expliosionradius, 2*Expliosionradius, 2*Expliosionradius);
    51.        
    52.         EnemyWhitinCollider.Clear();
    53.         try
    54.         {
    55.             sphereColldier = sphere.transform.GetComponent<SphereCollider>();
    56.             sphereColldier.radius = 0.5f;
    57.             Collider[] colliders = Physics.OverlapSphere(sphere.transform.position, sphereColldier.radius);
    58.             foreach (Collider collider in colliders)
    59.             {
    60.                 if (collider.gameObject.tag == "Enemy")
    61.                 {
    62.                     try
    63.                     {
    64.                         //Health enemyHeamth = collider.gameObject.GetComponent<Health>();
    65.                         EnemyWhitinCollider.Add(collider.gameObject);
    66.                     }
    67.                     catch
    68.                     {
    69.                         Debug.Log("No enemy within explosion radius at starts");
    70.                     }
    71.                 }
    72.             }
    73.         }
    74.         catch
    75.         {
    76.             Debug.Log("SphereCollider is null");
    77.         }
    78.         activateOutline = false;
    79.     }
    80.    
    81.     private void Update()
    82.     {
    83.         SphereRender.enabled = true;
    84.         //sphereColldier.radius = Expliosionradius;
    85.         if (sphereColldier == null)
    86.         {
    87.             sphereColldier = sphere.transform.GetComponent<SphereCollider>();
    88.         }
    89.         //
    90.         //Collider[] colliders = Physics.OverlapSphere(sphere.transform.position, sphereColldier.radius);
    91.         if (isOver || isSelected)
    92.         {  
    93.             Expliosionradius = (float)(2.5 * (playerScript.playerEntityData.PowerMagic / 100));
    94.             if (LastExpliosionradius != Expliosionradius)
    95.             {
    96.                 ExpliosionDamageMin = (int)(2 * (playerScript.playerEntityData.PowerMagic / 100));
    97.                 ExpliosionDamageMax = (int)(3 * (playerScript.playerEntityData.PowerMagic / 100));
    98.                 sphere.transform.localScale = new Vector3(2 * Expliosionradius, 2 * Expliosionradius, 2 * Expliosionradius);
    99.                
    100.                 LastExpliosionradius = Expliosionradius;
    101.                 activateOutline = false;
    102.             }
    103.            
    104.  
    105.  
    106.             if (!activateOutline)
    107.             {
    108.                 SphereRender.enabled = true;
    109.                 if (sphereColldier != null)
    110.                 {
    111.                     foreach (GameObject enemyHealth in EnemyWhitinCollider)
    112.                     {
    113.                         try
    114.                         {
    115.                             TargetBySpellScript targetBySpellScript = enemyHealth.gameObject.GetComponent<TargetBySpellScript>();
    116.                             targetBySpellScript.SetTarget(true);
    117.                             activateOutline = true;
    118.                         }
    119.                         catch
    120.                         {
    121.                             Debug.Log("No TargetBySpellScript found");
    122.                         }
    123.                     }
    124.                 }
    125.             }
    126.         }
    127.         else
    128.         {
    129.             SphereRender.enabled = false;
    130.         }
    131.     }
    132.    
    133.     private void OnTriggerEnter(Collider other)
    134.     {
    135.         if (other.gameObject.tag == "Enemy" || other.gameObject.tag == "Enemy Target")
    136.         {
    137.             try
    138.             {
    139.                 //Health enemyHeamth = other.gameObject.GetComponent<Health>();
    140.                 EnemyWhitinCollider.Add(other.gameObject);
    141.                 if (isOver || isSelected)
    142.                 {
    143.                     try
    144.                     {
    145.                         TargetBySpellScript targetBySpellScript = other.gameObject.GetComponent<TargetBySpellScript>();
    146.                         targetBySpellScript.SetTarget(true);
    147.                     }
    148.                     catch
    149.                     {
    150.                         Debug.Log("No TargetBySpellScript found");
    151.                     }
    152.                 }
    153.                
    154.             }
    155.             catch
    156.             {
    157.                 Debug.Log("Enemy without health entering self explosion sphere");
    158.             }
    159.         }
    160.     }
    161.  
    162.    
    163.     private void OnTriggerExit(Collider other)
    164.     {
    165.         if (other.gameObject.tag == "Enemy" || other.gameObject.tag == "Enemy Target")
    166.         {
    167.             try
    168.             {
    169.                 //Health enemyHeamth = other.gameObject.GetComponent<Health>();
    170.                 EnemyWhitinCollider.Remove(other.gameObject);
    171.                
    172.                 try
    173.                 {
    174.                     TargetBySpellScript targetBySpellScript = other.gameObject.GetComponent<TargetBySpellScript>();
    175.                     targetBySpellScript.SetTarget(false);
    176.                 }
    177.                 catch
    178.                 {
    179.                     Debug.Log("No TargetBySpellScript found");
    180.                 }
    181.                
    182.             }
    183.             catch
    184.             {
    185.                 Debug.Log("Enemy without health Exiting self explosion sphere");
    186.             }
    187.         }
    188.     }
    189.  
    190.     public void CastSpell(ScriptableCardData cardData)
    191.     {
    192.         autoCaster.CastCard();
    193.         if (playerScript.ConsumeRessource(cost))
    194.         {
    195.  
    196.             activateOutline = false;
    197.             ExpliosionDamageMin = (int)(2 * (playerScript.playerEntityData.PowerMagic / 100));
    198.             ExpliosionDamageMax = (int)(3 * (playerScript.playerEntityData.PowerMagic / 100));
    199.             foreach (GameObject go in EnemyWhitinCollider)
    200.             {
    201.                 try
    202.                 {
    203.                     TargetBySpellScript targetBySpellScript = go.gameObject.GetComponent<TargetBySpellScript>();
    204.                     targetBySpellScript.SetTarget(false);
    205.  
    206.                     Health targetHealth = targetBySpellScript.GetHealthComponent();
    207.                     float rndDamage = Random.Range(ExpliosionDamageMin, ExpliosionDamageMax);
    208.                     float[] damageoutput = new float[3];
    209.                     damageoutput[0] = rndDamage;
    210.                     damageoutput[1] = 0;
    211.                     damageoutput[2] = 0;
    212.  
    213.                     targetHealth.Damage(damageoutput, this.gameObject, 0, 0, Vector3.zero,false);
    214.                     isOver = false;
    215.                     isSelected = false;
    216.                 }
    217.                 catch
    218.                 {
    219.                     Debug.Log("No TargetBySpellScript found");
    220.                 }
    221.             }
    222.            
    223.             //Créé une explosion autour du joueur
    224.             try
    225.             {
    226.                 feedbakcPlayer.PlayFeedbacks();
    227.             }
    228.             catch
    229.             {
    230.                
    231.             }
    232.             isOver = false;
    233.             isSelected = false;
    234.  
    235.         }
    236.     }
    237.    
    238.     public bool CheckConditions( CastSpellDelegate castSpell, bool trigger, CallbackAutoCast autocastMethode)
    239.     {
    240.         bool output = false;
    241.         if (playerScript != null)
    242.         {
    243.             return output =  playerScript.CanConsumeRessource(cost);
    244.            
    245.         }
    246.         return false;
    247.     }
    248.  
    249.     public string GetCardCost()
    250.     {
    251.         return cost.ToString();
    252.     }
    253.  
    254.     public void OnMouseOver(bool trigger)
    255.     {
    256.         isOver = trigger;
    257.     }
    258.  
    259.     public bool ShouldICastOnSelect()
    260.     {
    261.         return CastOnSelect;
    262.     }
    263.  
    264.     public string SimulateStats(ScriptableCardData cardData, PlayerScript playerScript, DynamicEntityScript targetScript)
    265.     {
    266.         string output = "WORK IN PROGRESS";
    267.         return output;
    268.     }
    269.  
    270.     public void OnSelection(bool trigger)
    271.     {
    272.         isSelected = trigger;
    273.     }
    274.  
    275. }
    276.  
    277.    
    278.  
    And this one don't trigger :
    upload_2023-1-23_11-41-41.png

    Code (CSharp):
    1. using Assets._01_script.CardsScripts;
    2. using Assets._04_ScriptableObjects;
    3. using MoreMountains.Tools;
    4. using MoreMountains.TopDownEngine;
    5. using PixelCrushers;
    6. using System.Collections;
    7. using System.Collections.Generic;
    8. using TowerDefense.Assets.script;
    9. using UnityEngine;
    10. using static AutoCasterSccript;
    11. using static FireBallProjectilScript;
    12. using static SelectedCardScript;
    13. using static UnityEditor.PlayerSettings;
    14.  
    15. public class FireBallSpellScript : MonoBehaviour, ISpell
    16. {
    17.    
    18.     [SerializeField] PlayerScript playerScript;
    19.     [SerializeField] private float cost= 12;
    20.     [SerializeField] private FireBallSpawnerScript spawner;
    21.     [SerializeField] private float minDamage;
    22.     [SerializeField] private float maxDamage;
    23.     [SerializeField] private float Range;
    24.     [SerializeField] private float RangeLastFrame;
    25.     [SerializeField] private float speed;
    26.     [SerializeField] private float ExplosionRadius;
    27.  
    28.     [SerializeField] private bool displayOverlay;
    29.     [SerializeField] private MeshRenderer TargetSphere;
    30.     [SerializeField] private MeshRenderer radiusDisplay;
    31.  
    32.     [SerializeField] public LineRenderer lineRendererH;
    33.     [SerializeField] public LineRenderer lineRendererV;
    34.     [SerializeField] public AutoCasterSccript autoCaster;
    35.     [SerializeField] public PathManagerScript pathManager;
    36.  
    37.     [SerializeField] public MMLineRendererCircle rangeCircle;
    38.     public ConditionCheckDelegate conditionCheck;
    39.  
    40.     public Vector3 targetpos = new Vector3(0, 0, 0);
    41.  
    42.     private bool rangeUp = false;
    43.  
    44.     private HashSet<GameObject> EnemyWhitinCollider = new HashSet<GameObject>();
    45.     public void CastSpell(ScriptableCardData cardData )
    46.     {
    47.         autoCaster.CastCard();
    48.         if (playerScript.ConsumeRessource(cost))
    49.         {
    50.            spawner.FireToPos(targetpos, speed, 0.5f, ApplyDamage);
    51.         }
    52.        
    53.     }
    54.  
    55.     public bool CheckConditions(CastSpellDelegate castSpell, bool trigger, CallbackAutoCast autocastMethode)
    56.     {
    57.        
    58.         bool output = false;
    59.         if (playerScript != null)
    60.         {
    61.             output = playerScript.CanConsumeRessource(cost);
    62.             if (!output)
    63.             {
    64.                 return output;
    65.             }
    66.             else
    67.             {
    68.                 float distanceToTarget = Vector3.Distance(targetpos, playerScript.transform.position);
    69.                 if (distanceToTarget > Range)
    70.                 {
    71.                     Debug.Log("Target is out of range");
    72.                     if (trigger)
    73.                     {
    74.                         if (pathManager != null)
    75.                         {
    76.                             pathManager.SetTarget(targetpos);
    77.                         }
    78.                        
    79.                         autoCaster.SetConditionCheck(CheckConditions, castSpell, 0.3f, autocastMethode);
    80.                     }
    81.  
    82.                     return false;
    83.                 }
    84.                 else
    85.                 {
    86.                     if (!trigger)
    87.                     {
    88.                         castSpell();
    89.                     }
    90.                     autoCaster.CastCard();
    91.                     return true;
    92.                    
    93.                 }
    94.             }
    95.         }
    96.         return false;
    97.     }
    98.  
    99.     public string GetCardCost()
    100.     {
    101.         return cost.ToString();
    102.     }
    103.  
    104.     public void OnMouseOver(bool trigger)
    105.     {
    106.         // ne rien faire
    107.        
    108.     }
    109.  
    110.     public void OnSelection(bool trigger)
    111.     {
    112.         //Afficher l'overlay
    113.         displayOverlay = trigger;
    114.     }
    115.  
    116.     public bool ShouldICastOnSelect()
    117.     {
    118.         return false;
    119.     }
    120.  
    121.     public string SimulateStats(ScriptableCardData cardData, PlayerScript playerScript, DynamicEntityScript targetScript)
    122.     {
    123.         string output = "WORK IN PROGRESS";
    124.         return output;
    125.     }
    126.  
    127.     // Start is called before the first frame update
    128.     void Start()
    129.     {
    130.        
    131.         displayOverlay = false;
    132.         TargetSphere.gameObject.SetActive(false);
    133.         radiusDisplay.enabled = false;
    134.  
    135.         lineRendererH.startColor = Color.red;
    136.         lineRendererH.endColor = Color.red;
    137.  
    138.         // set width of the renderer
    139.         lineRendererH.startWidth = 0.02f;
    140.         lineRendererH.endWidth = 0.02f;
    141.         //
    142.         //lineRendererV.startColor = Color.red;
    143.         //lineRendererV.endColor = Color.red;
    144.  
    145.         // set width of the renderer
    146.         lineRendererV.startWidth = 0.02f;
    147.         lineRendererV.endWidth = 0.02f;
    148.         conditionCheck = CheckConditions;
    149.  
    150.         EnemyWhitinCollider.Clear();
    151.  
    152.         Collider[] colliders = Physics.OverlapSphere(TargetSphere.gameObject.transform.position, ExplosionRadius);
    153.         foreach (Collider collider in colliders)
    154.         {
    155.             try
    156.             {
    157.                 if (collider.gameObject.tag == "Enemy" || collider.gameObject.tag == "Enemy Target")
    158.                 {
    159.                     TargetBySpellScript targetBySpellScript = collider.gameObject.GetComponent<TargetBySpellScript>();
    160.                     EnemyWhitinCollider.Add(collider.gameObject);
    161.                 }
    162.             }
    163.             catch
    164.             {
    165.                 //Debug.Log("No TargetBySpellScript found");
    166.             }
    167.         }
    168.     }
    169.  
    170.     public void ApplyDamage(Vector3 Pos)
    171.     {  
    172.         Collider[] colliders = Physics.OverlapSphere(Pos, ExplosionRadius);
    173.         foreach (Collider collider in colliders)
    174.            
    175.         {
    176.             try
    177.             {
    178.                 TargetBySpellScript targetBySpellScript = collider.gameObject.GetComponent<TargetBySpellScript>();
    179.                 targetBySpellScript.SetTarget(false);
    180.  
    181.                 Health targetHealth = targetBySpellScript.GetHealthComponent();
    182.                 float rndDamage = Random.Range(minDamage, maxDamage);
    183.                 float[] damageoutput = new float[3];
    184.                 damageoutput[0] = rndDamage;
    185.                 damageoutput[1] = 0;
    186.                 damageoutput[2] = 0;
    187.  
    188.                 targetHealth.Damage(damageoutput, this.gameObject, 0, 0, Vector3.zero, false);
    189.                 displayOverlay = false;
    190.             }
    191.             catch
    192.             {
    193.                 Debug.Log("No TargetBySpellScript found");
    194.             }
    195.         }
    196.     }
    197.  
    198.     // Update is called once per frame
    199.     void Update()
    200.     {
    201.        
    202.         if (displayOverlay)
    203.         {
    204.            
    205.             minDamage = (int)(4 * (playerScript.playerEntityData.PowerMagic / 100));
    206.             maxDamage = (int)(5 * (playerScript.playerEntityData.PowerMagic / 100));
    207.             ExplosionRadius = (float)(1.8 * (playerScript.playerEntityData.PowerMagic / 100));
    208.             this.transform.localScale = new Vector3(2 * ExplosionRadius, 2 * ExplosionRadius, 2 * ExplosionRadius);
    209.             Range = (float)(7 * (playerScript.playerEntityData.PowerMagic / 100));
    210.            
    211.             rangeCircle.HorizontalRadius =  Range;
    212.             rangeCircle.VerticalRadius =  Range;
    213.             if (rangeCircle != null && !rangeUp)
    214.             {              
    215.                 rangeCircle.enabled = true;
    216.                 rangeUp = true;
    217.             }
    218.             if (RangeLastFrame != Range)
    219.             {
    220.                 rangeCircle.DrawCircle();
    221.             }
    222.             RangeLastFrame = Range;
    223.             //cast a ray from the player to the mouse position
    224.             //get the position of the mouse
    225.             Ray ray0 = Camera.main.ScreenPointToRay(Input.mousePosition);
    226.             RaycastHit hit0;
    227.             if (Physics.Raycast(ray0, out hit0, Mathf.Infinity))
    228.             {
    229.                
    230.             }
    231.             //cast a ray from the player to the mouse position
    232.             Ray ray = new Ray(playerScript.transform.position+ new Vector3(0,1,0), new Vector3(hit0.point.x - playerScript.transform.position.x+1, 0, hit0.point.z - playerScript.transform.position.z));
    233.             RaycastHit hit;
    234.             if (Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << LayerMask.NameToLayer("Enemies"))
    235.                 || Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << LayerMask.NameToLayer("Target"))
    236.                 || Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << LayerMask.NameToLayer("Terrain")))
    237.             {
    238.                 //if the ray hits something
    239.                 //Debug.DrawLine(playerScript.transform.position, hit0.point, Color.red);
    240.                 lineRendererH.gameObject.SetActive(true);
    241.                 lineRendererV.gameObject.SetActive(true);
    242.                 lineRendererH.SetPosition(0, this.transform.position + new Vector3(0, 1, 0));
    243.                
    244.                 //Debug.DrawLine(hit.point, hit.point - new Vector3(0,-2,0), Color.red);
    245.                
    246.                 //draw a line from the player to the point where the ray hit
    247.                 //draw a sphere at the point where the ray hit
    248.                 TargetSphere.gameObject.SetActive(true);
    249.                
    250.                 //draw a sphere at the point where the ray hit
    251.                 radiusDisplay.enabled = true;
    252.  
    253.                 float DistanceWithMouse = Vector3.Distance(new Vector3(hit0.point.x, playerScript.transform.position.y + 1, hit0.point.z), playerScript.transform.position );
    254.                 float DistanceWithHit = Vector3.Distance(hit.point, playerScript.transform.position);
    255.                 this.gameObject.transform.localScale = new Vector3(2 * ExplosionRadius, 2 * ExplosionRadius, 2 * ExplosionRadius);
    256.  
    257.                 if (DistanceWithMouse < DistanceWithHit)
    258.                 {
    259.                     this.gameObject.transform.position = new Vector3(hit0.point.x, playerScript.transform.position.y + 1, hit0.point.z);
    260.                     TargetSphere.gameObject.transform.position = new Vector3(hit0.point.x, playerScript.transform.position.y + 1, hit0.point.z);
    261.  
    262.                    
    263.                 }
    264.                 else
    265.                 {
    266.                     this.gameObject.transform.position = hit.point;
    267.                     TargetSphere.gameObject.transform.position = hit.point;
    268.  
    269.                    
    270.                 }
    271.                 lineRendererH.SetPosition(1, this.transform.position + new Vector3(0, 1, 0) + 10 * (TargetSphere.gameObject.transform.position - (this.transform.position + new Vector3(0, 1, 0))));
    272.                 lineRendererV.SetPosition(0, TargetSphere.gameObject.transform.position);
    273.                 lineRendererV.SetPosition(1, TargetSphere.gameObject.transform.position - new Vector3(0, 2, 0));
    274.                
    275.                
    276.  
    277.             }
    278.             else
    279.             {
    280.                 //if the ray does not hit anything
    281.                 Debug.DrawLine(ray.origin, ray.origin + ray.direction * Range, Color.red);
    282.                 //draw a line from the player to the point where the ray would hit
    283.             }
    284.             targetpos = TargetSphere.transform.position;
    285.         }
    286.         else
    287.         {
    288.             if (rangeUp)
    289.             {
    290.                 rangeCircle.enabled = false;
    291.                 rangeUp = !rangeUp;
    292.             }
    293.            
    294.             TargetSphere.gameObject.SetActive(false);
    295.             radiusDisplay.enabled = false;
    296.             lineRendererH.gameObject.SetActive(false);
    297.             lineRendererV.gameObject.SetActive(false);
    298.         }
    299.     }
    300.  
    301.     private void OnTriggerEnter(Collider other)
    302.     {
    303.         if (other.gameObject.tag == "Enemy" || other.gameObject.tag == "Enemy Target")
    304.         {
    305.             try
    306.             {
    307.                 //Health enemyHeamth = other.gameObject.GetComponent<Health>();
    308.                 EnemyWhitinCollider.Add(other.gameObject);
    309.                 if (displayOverlay)
    310.                 {
    311.                     try
    312.                     {
    313.                         TargetBySpellScript targetBySpellScript = other.gameObject.GetComponent<TargetBySpellScript>();
    314.                         targetBySpellScript.SetTarget(true);
    315.                     }
    316.                     catch
    317.                     {
    318.                         Debug.Log("No TargetBySpellScript found");
    319.                     }
    320.                 }
    321.  
    322.             }
    323.             catch
    324.             {
    325.                 Debug.Log("Enemy without health entering self explosion sphere");
    326.             }
    327.         }
    328.     }
    329.  
    330.     private void OnTriggerExit(Collider other)
    331.     {
    332.         if (other.gameObject.tag == "Enemy" || other.gameObject.tag == "Enemy Target")
    333.         {
    334.             try
    335.             {
    336.                 //Health enemyHeamth = other.gameObject.GetComponent<Health>();
    337.                 EnemyWhitinCollider.Remove(other.gameObject);
    338.  
    339.                 try
    340.                 {
    341.                     TargetBySpellScript targetBySpellScript = other.gameObject.GetComponent<TargetBySpellScript>();
    342.                     targetBySpellScript.SetTarget(false);
    343.                 }
    344.                 catch
    345.                 {
    346.                     Debug.Log("No TargetBySpellScript found");
    347.                 }
    348.  
    349.             }
    350.             catch
    351.             {
    352.                 Debug.Log("Enemy without health Exiting self explosion sphere");
    353.             }
    354.         }
    355.     }
    356. }
    357.  
    I can't see any differences that could exeplain why the second doesn't work.
    Maybe a fresh eye could see one.

    Thanks for your help .
     
  2. Pierre-Marie

    Pierre-Marie

    Joined:
    Aug 3, 2015
    Posts:
    52
    OMG I found it when I reread the post, the sphere colldier radius is not update in the second so the solldier have a zéro radius.
    It solve it...