disable script from another script unity with many tags, enable / disable one of the scripts found in many Objects with the tag == "ABC"

hi all, that is true one or two or three Object mounted Script. has solution

  • many Object same one tag==“IsGun”, all Object attach Script “AttackWeapon.cs”
  • Those Objects attach the same Script.

in “SetActiveScripts.cs” script I used FindGameObjectsWithTag to find Objects with the tag == “isGun”
and I also enabled == false when I started the game.

and when I want to collider with an Object that is in the == “isGun” tag, then that all Object’s Scripts enable == true, but I just want whichever one I touch will enable, and the remaining disabled…
Thanks for all the help.

using System.Collections;
        using System.Collections.Generic;
        using UnityEngine;
        
        public class SetActiveScripts : MonoBehaviour
        {
            public GameObject[] gun;
            public itemObject id;
            void Awake()
            {
                
                gun = GameObject.FindGameObjectsWithTag("isGun");
                for (int i = 0; i < gun.Length; i++)
                {
                    if (gun*.GetComponent<AttackWeapon>() != null)*

{
gun*.GetComponent().enabled = false;*
Debug.Log(“abs”);
}
else
{
Debug.LogWarning(gun + " does not contain a component of type Patrol. Please add one.");
}
}

}
void OnTriggerEnter(Collider other)
{
if (other.tag==“isGun” && id.weaponID==1)
{
for (int i = 0; i < gun.Length; i++)
{
if (gun*.GetComponent() != null)*
{
gun*.GetComponent().enabled = true;*
Debug.Log(“AK”);
break;
}
else
{
Debug.LogWarning(gun + " does not contain a component of type Patrol. Please add one.");
}
}
}
}
}

1 Answer

1

anyone help me??pls