Exemple #1
0
    // Awake is called before the first frame update
    private void Awake()
    {
        // Get references to the game objects and their components
        dynamicAgent     = GameObject.Find("DynamicAgent");
        dynAgComp        = dynamicAgent.GetComponent <DynamicAgent>();
        targetController = GameObject.Find("TargetController");
        stcComp          = targetController.GetComponent <StaticTargetController>();

        // Deactivate the game's game objects, so the game doesn't start
        // running right away
        Stop();

        // Is this an optimization play or a single game play?
        if (optimize)
        {
            // Change the time scale as specified in the editor
            Time.timeScale = timeScale;

            // Should we show the game will optimizing?
            if (!showGame)
            {
                // If not, disable the camera
                GameObject goCam = GameObject.Find("Main Camera");
                goCam.SetActive(false);
            }

            // Instantiate a new C# native random number generator, to be used
            // by the optimization thread
            threadRnd = new SRandom();
        }
    }
    // Target is destroyed if someone collides with it
    private void OnTriggerEnter2D(Collider2D other)
    {
        StaticTargetController controller =
            GetComponentInParent <StaticTargetController>();

        controller.NotifyDestructionBy(other.attachedRigidbody);

        Destroy(this.gameObject);
    }