How to switch off the Traffic System

8136785--1056044--unity.JPG I have a drive simulator. In this project there is also TrafficSpawner e iTsManager

If I try to start the game, I can see some cars walking, now I need to manage traffic from my gameManager class and I need to activate or deactivate the traffic from code when the game started. So this is my gameManager class:

using System.Collections.Generic;
using UnityEngine;

namespace DrivingTest
{
    public class TDFCLNCManager : CLNCManager, ITestEnd
    {
        //public GameObject trafficLights;
        public GameObject[] disableBarricades;
        public GameObject[] enableBarricades;

        private bool endCLNCTest;
        public override void Awake()
        {
            car = TDFManager.Instance.car;
        }
        public override void Start()
        {
            base.Start();
            endTime = Time.time;
            trafficSystem.SetActive(false);
            trafficSpawner.gameObject.SetActive(false);
        }
     

        protected override void SetUpCar()
        {
            foreach (var component in SceneObjects.activeSceneObjects.sceneObjects)
            {
                if (component.GetComponent<TSTrafficSpawner>())
                {
                    component.SetActive(true);
                    component.transform.SetParent(car.transform);
                    component.transform.localPosition = Vector3.zero;
                }
                else if (component.GetComponent<TSMainManager>())
                {
                    component.SetActive(true);
                }
            }
            trafficSpawner.SetParent(car.transform);
            trafficSpawner.localPosition = Vector3.zero;
            trafficSpawner.gameObject.SetActive(false);
        }

        protected override void OnSceneLoaded(eTESTS test)
        {
            Debug.Log("onScene TDF Loaded");
        }

        public override void OnEnable()
        {
            base.OnEnable();
            EndTaskTrigger.endTaskTriggerAction += EnableDisableBarricades;
            //TrafficLightTrigger.OnTrafficLightTriggerEnter += OnTrafficLightEnter;
        }

        public override void OnDisable()
        {
            base.OnDisable();
            EndTaskTrigger.endTaskTriggerAction -= EnableDisableBarricades;
            //TrafficLightTrigger.OnTrafficLightTriggerEnter -= OnTrafficLightEnter;
        }

        private void OnTrafficLightEnter()
        {
            //trafficLights.SetActive(true);
        }

        public override void Update()
        {

        }

        private void EnableDisableBarricades()
        {
            foreach (var item in disableBarricades)
            {
                item.SetActive(false);
            }
            foreach (var item in enableBarricades)
            {
                item.SetActive(true);
            }
        }

        protected override void GetApiParams()
        {
            InitEventData();
            StartCoroutine(GetCarData());
        }


        protected void InitEventData()
        {
            //proviamo a mettere qui
            trafficSystem.SetActive(false);
            trafficSpawner.gameObject.SetActive(false);
            if (testComplexity == eComplexity.Low)
            {
                return;
            }
            //
            for (int i = 0; i < eventDataa.Length; i++)
            {
                eventDataa[i].eventName = ((EventDataNames)i).ToString();
            }
        }

        protected override bool HasTestEnded()
        {
            return endCLNCTest;
        }


        protected override void TestOver()
        {
            //base.TestOver();

        }

  

    }
}

Now as you can see in InitEventData I try to set traffic to false,

in setupCar method I try to set frattif to false and on start method, but I continue to display traffic system on my game.

Ask the creator of the asset

1 Like

What did you means?

If the system is written by you, you know how to use it.

If you don’t know how to use it, then it was written by someone else. Meaning you probably bought it off asset store.

In this case you’d need to ask the author for techsupport.

1 Like

I meant this is the ITS traffic asset related code and as such you should contact the author, nobody else will be able to help you as reliably as they will. This is not an issue for the unity forums but one for their support.

Thanks and good luck :slight_smile: