Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (portalTime <= 0)
        {
            orangePortal.SetActive(false);
            GetComponent <SpriteRenderer>().enabled = false;
            GetComponent <BoxCollider>().enabled    = true;
        }
        else
        {
            portalTime -= Time.deltaTime;
        }
        if (blocRigidbody != null && bloc != null && blocRigidbody.velocity.magnitude <= 0.01f)
        {
            GetComponent <SpriteRenderer>().enabled = true;
            orangePortal.SetActive(true);
            List <Bloc> blocs = new List <Bloc>();
            blocs.Add(bloc);

            for (int i = 1; i < bloc.size; i++)
            {
                Bloc newBloc = Instantiate(bloc);
                newBloc.InitText(bloc.GetInstanceID().ToString());
                newBloc.gameObject.SetActive(false);
                blocs.Add(newBloc);
            }

            int startIdx = mM.AllocateMemory(blocs);

            if (startIdx != -1)
            {
                //GameObject key = Instantiate(keyPrefab, new Vector3(0, 0, 0), new Quaternion());
                //key.transform.Find("KeyModel").GetComponent<Renderer>().material.color = bloc.GetComponent<Renderer>().material.color;
                //key.transform.Find("KeyText").GetComponent<TextMesh>().text = bloc.GetComponentInChildren<TextMesh>().text;
                foreach (Bloc b in blocs)
                {
                    b.gameObject.SetActive(true);
                }
            }
            else
            {
                print("no more space");
                foreach (Bloc b in blocs)
                {
                    Destroy(b);
                }
                Destroy(bloc.prog.gameObject);
                Destroy(bloc.gameObject);
            }



            bloc          = null;
            blocRigidbody = null;
        }
    }