Exemple #1
0
    private void InitBackground(BackgroundLayer layer)
    {
        GameObject gameObjRef = layer.gameObjRef;
        GameObject gameObject1, gameObject2;

        gameObject1 = Instantiate(gameObjRef, Vector3.up * layer.yPos, Quaternion.identity);
        gameObject1.transform.SetParent(this.transform);
        gameObject1.GetComponent <ScrollingObject>().scrollRatio = layer.scrollSpeedRatio;
        gameObject1.GetComponent <ScrollingObject>().row         = layer.row;

        //layer.width = gameObject1.GetComponent<BoxCollider2D>().size.x;
        //layer.height = gameObject1.GetComponent<BoxCollider2D>().size.y;
        if (layer.row == 0)
        {
            Utils.backgroundSize.x = layer.GetWidth();  // gameObject1.GetComponent<BoxCollider2D>().size.x;
            Utils.backgroundSize.y = layer.GetHeight(); // gameObject1.GetComponent<BoxCollider2D>().size.y;
        }

        Vector3 pos = Vector3.right * layer.GetWidth() + Vector3.up * layer.yPos;

        gameObject2 = Instantiate(gameObjRef, pos, Quaternion.identity);
        gameObject2.transform.SetParent(this.transform);
        gameObject2.transform.Rotate(Vector3.up * 180f);
        gameObject2.GetComponent <ScrollingObject>().scrollRatio = layer.scrollSpeedRatio;
        gameObject2.GetComponent <ScrollingObject>().row         = layer.row;
    }