Raycast ignore Box Collider is triggert but dont ignore the Gameobject

Hi Community,

its little bit frustrating. I dont know what can i do against it.

I have an object that got an big size box collider with the option isTriggert. If i hit the box collider with my raycast it nothing happen but i can hit my gameobject with it.

Now i seaching through the whole internet but i dont find any good solution.

First try to solve the problem :

Uncheck the Queries Hit Triggers. ! It works with ignore the box collider but i CANT select my gameobject because the option isTriggert is enable

if i disable the option isTriggert on the gameobject it will work but I need to enable it.

Any good idea ???

I’m a little confused… do you want the raycast to hit the trigger collider? or not to hit the trigger collider?

So guys i´ve got another problem. I dont fix this Upgrade tower yet but i bit more confident.

My problem is that when i destroy my boosttower then all Tower in his radius should get - boostAttack. Because they get a buff of + boostAttack.

All Towers are in my List and when one tower is in the boosttower range he will add to the list. When i detroy the boosttower all tower should lose his boost. It doesnt work because if i print out the length of the list its always 0 at the end of the GetDestroyed() method although I add tower in the list.

In the TowerRangeEnter method i print all time the current length of the list out and its raising correctly.

I dont know but is it possible that list lose some items in runtime ? :smile: is my ram broken?

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class TrapTower : Tower {

    private float flSlowBetweenNextSlow = 1.0f;
    private float flSlowTimer = 0.0f;
    private Collider[] col;
    private GameObject[] gaAllTowers;
    private float iRangeSize = 30;
    private float flDmgUpgradeTowerInRange = 2.0f;
    private bool bFirstRun = true;
    private List<GameObject> liTowerInRange;

    void Awake(){
        enTypeTower = EnumCollection.TypeTower.SlowTrap;
        liTowerInRange = new List<GameObject> ();
    }

    private void OnDrawGizmos(){
        Gizmos.color = Color.yellow;
        Gizmos.DrawWireSphere (transform.position, 100);
    }
    void SearchingTowerAwake(){
        col = Physics.OverlapSphere (this.transform.position, 50);
        foreach (Collider peter in col) {
            if (peter.gameObject.tag == "Tower") {
                if (peter.gameObject.GetComponent<ShootTower> ().GetIsInRange () == EnumCollection.RangeCondition.No) {
                    peter.GetComponent<ShootTower> ().SetDamageByTower (flDmgUpgradeTowerInRange);
                    peter.GetComponent<ShootTower> ().SetIsInRange (EnumCollection.RangeCondition.Yes);
                    liTowerInRange.Add (peter.gameObject);
                }
            }
        }
        Debug.Log (liTowerInRange.Count);
    }

    void SetBoxColliderSize(float iSize){
        BoxCollider boSize;
        Transform trRange;
        trRange = this.gameObject.transform.FindChild ("r_Range");
        boSize = trRange.gameObject.GetComponent<BoxCollider> ();
        boSize.size = new Vector3 (iSize, 1, iSize);
    }


    void OnCollisionStay(Collision col){
        CheckTrapVersion (col.gameObject);
    }

    void OnCollisionEnter(Collision col) {
        CheckTrapVersion (col.gameObject);
        TowerRangeEnter (col.gameObject);
    }

    void OnCollisionExit(Collision col) {
        CheckTrapVersion (col.gameObject);
        if (CheckCollisionTitan(col.gameObject)) {
            if (enTypeTower == EnumCollection.TypeTower.SlowTrap) {
                col.gameObject.GetComponent<Titans> ().SetSlowTime (false);
            }
        }
    }

    void Update(){
        flFireCoolDown += Time.deltaTime;
        if (this.getTypeTower () == EnumCollection.TypeTower.RangeTrap && bFirstRun ) {
            liTowerInRange = new List<GameObject> ();
            //SearchingTowerAwake ();
            SetBoxColliderSize (iRangeSize);
            bFirstRun = false;
        }
    }


    public void TowerRangeEnter(GameObject gaTower){
        if (liTowerInRange != null) {
            if (CheckCollisionTower (gaTower)) {
                if (gaTower.GetComponent<ShootTower> ().GetIsInRange () == EnumCollection.RangeCondition.No) {
                    Debug.Log ("Tower Upgrade");
                    gaTower.GetComponent<ShootTower> ().SetDamageByTower (flDmgUpgradeTowerInRange);
                    gaTower.GetComponent<ShootTower> ().SetIsInRange (EnumCollection.RangeCondition.Yes);
                    liTowerInRange.Add (gaTower.gameObject);

                    Debug.Log (liTowerInRange.Count);
                }
            }
        }
    }

    public void TowerRangeExist(GameObject gaTower){
            if (gaTower.GetComponent<ShootTower> ().GetIsInRange () == EnumCollection.RangeCondition.Yes) {
                Debug.Log ("Tower Leave");
                gaTower.GetComponent<ShootTower> ().SetLoseDamageByTower (flDmgUpgradeTowerInRange);
                gaTower.GetComponent<ShootTower> ().SetIsInRange (EnumCollection.RangeCondition.No);
            }
    }

    bool CheckCollisionTitan(GameObject gaTitan){
        if (gaTitan.tag == "Titans")
            return true;
        else
            return false;
    }

    bool CheckCollisionTower(GameObject gaTower){
        if (gaTower.tag == "Tower")
            return true;
        else
            return false;
    }

    public void GetDestroyed(){
        Debug.Log ("ON DEYTROY " + liTowerInRange.Count);
        foreach(GameObject gaTower in liTowerInRange){
            TowerRangeExist (gaTower);
        }
        liTowerInRange.Clear ();
        Destroy (this.gameObject);
    }
       

//        col = Physics.OverlapSphere (this.gameObject.transform.position, iRangeSize);
//
//        if (bFirstRun) {
//            foreach (Collider coTower in col) {
//                if (coTower.gameObject.tag == "Tower") {
//                    coTower.gameObject.GetComponent<ShootTower> ().SetDamageByTower (flDmgUpgradeTowerInRange);
//                    coTower.gameObject.GetComponent<ShootTower> ().SetIsInRange(EnumCollection.RangeCondition.Yes);
//                    liTowerInRange.Add (coTower.gameObject);
//                }
//                bFirstRun = false;
//            }
//        } else {
//            foreach(GameObject gaTower in liTowerInRange){
//                    foreach (Collider coTower in col) {
//                        if (coTower.gameObject.tag == "Tower") {
//                            if (gaTower.GetInstanceID() == coTower.gameObject.GetInstanceID()) {
//                                bNichtGefunden = true;
//                            }
//                        }
//                        if (!bNichtGefunden) {
//                            gaTower.GetComponent<ShootTower> ().SetLoseDamageByTower (flDmgUpgradeTowerInRange);
//                            gaTower.GetComponent<ShootTower> ().SetIsInRange (EnumCollection.RangeCondition.No);
//                        } else {
//                            foreach (Collider coTower2 in col) {
//                                if (coTower2.gameObject.tag == "Tower") {
//                                    foreach (GameObject gaTower2 in liTowerInRange) {
//                                        if (coTower2.gameObject.GetInstanceID () == gaTower2.GetInstanceID ()) {
//                                            bNeuerGefunden = true;
//                                        }
//
//                                        if (!bNeuerGefunden) {
//                                            coTower2.gameObject.GetComponent<ShootTower> ().SetDamageByTower (flDmgUpgradeTowerInRange);
//                                            coTower2.gameObject.GetComponent<ShootTower> ().SetIsInRange (EnumCollection.RangeCondition.Yes);
//                                        }
//                                    }
//                                    bNeuerGefunden = false;
//                                }
//                            }
//                        }
//                    }
//                bNichtGefunden = false;
//            }
//        }

//        liTowerInRange.Clear ();
//        foreach (Collider coTower in col) {
//            if (coTower.gameObject.tag == "Tower") {
//                liTowerInRange.Add (coTower.gameObject);
//            }
//        }
//
//    }

    void CheckTrapVersion(GameObject gaTitan){
        if (CheckCollisionTitan(gaTitan)) {
            switch (enTypeTower) {
            case EnumCollection.TypeTower.FireTrap:
                StartFireTrap (gaTitan);
                break;
            case EnumCollection.TypeTower.SlowTrap:
                StartSlowTrap (gaTitan);
                break;
            }
        }
    }

    void StartFireTrap(GameObject gaTitan){
        if (flFireCoolDown >= flFireTrapDmgTime) {
            gaTitan.GetComponent<Titans> ().getHit (flFireTrapDmgPerSecond, this);
            flFireCoolDown = 0.0f;
        }
    }

    void StartSlowTrap(GameObject gaTitan){
        if (!gaTitan.GetComponent<Titans> ().GetSlowTime () && gaTitan.GetComponent<Titans>().GetRestSlow()) {
            gaTitan.GetComponent<Titans> ().getHit (0.0f, this);
        } else if (gaTitan.GetComponent<Titans> ().GetSlowTime ()){
            flSlowTimer += Time.deltaTime;
            if (flSlowTimer >= flSlowBetweenNextSlow) {
                gaTitan.GetComponent<Titans> ().SetSlowTime (false);
                gaTitan.GetComponent<Titans> ().SetRestSlow (true);
                flSlowTimer = 0.0f;
            }
        }
    }
}