Ejemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     if (mirror != null)
     {
         Mirror_warp mw = (Mirror_warp)(mirror.gameObject.GetComponent("Mirror_warp"));
         if (mw != null)
         {
             mw.warped = false;
         }
     }
 }
Ejemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        string time = SceneManagerWithParameters.GetParam("SongTime");

        if (time != "")
        {
            song.time = float.Parse(time);
        }
        song.Play();
        objectDict = new Dictionary <string, string>();
        string name   = SceneManager.GetActiveScene().name;
        string active = SceneManagerWithParameters.GetParam(name + "Active");

        if (active == "")
        {
            GameObject[] destroyable = GameObject.FindGameObjectsWithTag("Breakable");
            foreach (GameObject des in destroyable)
            {
                if (des.GetComponent <SpriteRenderer>().enabled == false)
                {
                    objectDict.Add(des.name, "Destroyed");
                }
                else
                {
                    objectDict.Add(des.name, des.transform.position.ToString());
                }
            }
        }
        else
        {
            string[] sArray = active.Split(';');
            foreach (string s in sArray)
            {
                string[] unit = s.Split(':');
                objectDict.Add(unit[0], unit[1]);
            }
        }


        player = GameObject.Find("Player");
        if (SceneManagerWithParameters.GetParam("warped").Equals("true"))
        {
            mirror = GameObject.Find(SceneManagerWithParameters.GetParam("location"));
            Mirror_warp c = (Mirror_warp)mirror.gameObject.GetComponent("Mirror_warp");
            if (c != null)
            {
                c.warped = true;
            }
            if (SceneManagerWithParameters.GetParam("type").Equals("sideways"))
            {
                float ydiff = float.Parse(SceneManagerWithParameters.GetParam("vertposition"));
                if (SceneManagerWithParameters.GetParam("orientation").Equals("left"))
                {
                    player.transform.position = new Vector2(mirror.transform.position.x + c.distance, mirror.transform.position.y + ydiff);
                }
                else
                {
                    player.transform.position = new Vector2(mirror.transform.position.x - c.distance, mirror.transform.position.y + ydiff);
                }
                string velString = SceneManagerWithParameters.GetParam("velocity");
                player.GetComponent <Rigidbody2D>().velocity = StringToVector2(velString);
            }
            else
            {
                float xdiff = float.Parse(SceneManagerWithParameters.GetParam("horiposition"));

                player.transform.position = new Vector2(mirror.transform.position.x + xdiff, mirror.transform.position.y + c.distance);
                string velString = SceneManagerWithParameters.GetParam("velocity");

                Rigidbody2D playerRb = player.GetComponent <Rigidbody2D>();
                Vector2     v        = StringToVector2(velString);
                v = new Vector2(v.x, -v.y);
                playerRb.velocity = v;
            }
            string destroyed = SceneManagerWithParameters.GetParam("Destroyed");
            if (destroyed != "")
            {
                string[] sArray = destroyed.Split(',');
                foreach (string i in sArray)
                {
                    obj           = GameObject.Find(i);
                    objectDict[i] = SceneManagerWithParameters.GetParam(i);
                    Vector3 pos = StringToVector3(SceneManagerWithParameters.GetParam(i));
                }
                destroyed = "";
                SceneManagerWithParameters.SetParam("Destroyed", destroyed);
            }
        }
        foreach (string k in objectDict.Keys)
        {
            obj = GameObject.Find(k);
            if (objectDict[k].Equals("Destroyed"))
            {
                obj.GetComponent <Rigidbody2D>().simulated  = false;
                obj.GetComponent <SpriteRenderer>().enabled = false;
                obj.GetComponent <BoxCollider2D>().enabled  = false;
            }
            else
            {
                obj.transform.position = StringToVector3(objectDict[k]);

                obj.GetComponent <Rigidbody2D>().simulated  = true;
                obj.GetComponent <SpriteRenderer>().enabled = true;
                obj.GetComponent <BoxCollider2D>().enabled  = true;
            }
        }
    }