Exemple #1
0
    private void SetUpMyTri(Color[,] triDataSet)
    {
        for (int i = 0; i < triDataSet.GetLength(0); i++)
        {
            for (int j = 0; j < triDataSet.GetLength(1); j++)

            {
                if (triDataSet[i, j] == null)
                {
                    Debug.Log("No Colour assigned so not instantiating this array element");
                    continue;
                }               //currently untested

                //alot of the code below should be replaceable with something that looks like this
                //once gamespace is right
                // GameObject newTri = GameObject.Instantiate(uncoloredTri, position(), Quaternion.identity, this.transform to local);

                //building coords from index
                //later will need to put in the adjuster
                float myX = (float)i;
                float myY = (float)j;


                //this makes it relative to this TriCluster Transform but surely can do that in the instantiation
                Vector3 position = new Vector3((myX + this.gameObject.transform.position.x), (myY + this.gameObject.transform.position.y), (this.gameObject.transform.position.z));

                //this scales it but we shouldnt need this because we should set the gamespace right
                float   myXScaled = position.x * scaleMultiplierX;
                float   myYScaled = position.y * scaleMultiplierY;
                Vector3 positionUnorientatedButScaledAndRelative = new Vector3(myXScaled, myYScaled, position.z); //bad nammed put instages



                GameObject newTri = GameObject.Instantiate(uncoloredTri, positionUnorientatedButScaledAndRelative, Quaternion.identity, this.transform);

                //invert triangles in positions needing inverting
                //this step could trip us up if we are not reinstantiating whole object if there is an impact but could be okay

                //this flips even triangles upsidedown if we use ! could do opposite
                if ((i + j) % 2 < 0.1f)


                {
                    newTri.transform.localScale = new Vector3(newTri.transform.localScale.x, -1 * newTri.transform.localScale.y, newTri.transform.localScale.z);
                }

                BadCodeTri2 newTriScript = newTri.GetComponent <BadCodeTri2>();
                newTriScript.myColor   = triDataSet[i, j];
                newTriScript.myColor.a = 1;  //only reason i need to do this is coz i havent looked up how to update new prefabs

                newTriScript.enabled = true; // why enabled what does it do in start and update?
            }
        }


        //CreateCompositeRBSoChildrenMoveWithParent();
    }
Exemple #2
0
    void Start() //maybe a set up method to replace constructor
    {
        Debug.Log(this + " is turned on and active");
        badGrid = gameObject.GetComponent <BadGrid>();


        positionUnorientatedButScaledAndRelative = new Vector3 [positions.Length];

        /*
         * foreach (BadTriData data in badTriData) {
         * GameObject newTri = GameObject.Instantiate(uncoloredTri, data.posRelParent, Quaternion.identity);
         *  BadCodeTri2 newTriScript = newTri.GetComponent<BadCodeTri2>();
         * newTriScript.myColor = data.myColor;
         *  newTriScript.enabled = true;
         *
         *
         *
         *
         * }
         */
        for (int i = 0; i < colors.Length; i++)
        {
            //this should work fine because we would feed the code exact grid locations
            //but lets put in the grid anyway for seeing it work

            positions[i] = new Vector3((positions[i].x + this.gameObject.transform.position.x), (positions[i].y + this.gameObject.transform.position.y), (positions[i].z));
            scaledX      = positions[i].x * scaleMultiplierX;
            scaledY      = positions[i].y * scaleMultiplierY;
            positionUnorientatedButScaledAndRelative[i] = new Vector3(scaledX, scaledY, positions[i].z); //bad nammed put instages



            GameObject newTri = GameObject.Instantiate(uncoloredTri, positionUnorientatedButScaledAndRelative[i], Quaternion.identity, this.transform);


            //do the if twice as will be a different inversion per line
            // trying to fix last pair of triangles not upside down
            //replace !=0 with >0.1f
            //using original coord system ad it works so assume it rounding

            // if ((placePositionUnorientatedButScaled[i].x/scaleMultiplierX) % 2  < 0.1f) {
            if (Mathf.Abs(positions[i].x) % 2 < 0.1f)
            {
                newTri.transform.localScale = new Vector3(newTri.transform.localScale.x, -1 * newTri.transform.localScale.y, newTri.transform.localScale.z);

                //invert triangle
                //rotation
                //or multiply scale x by -1?
            }
            if (Mathf.Abs(positions[i].y) % 2 < 0.1f)  // doesnt always work probably due to rounding
            {
                newTri.transform.localScale = new Vector3(newTri.transform.localScale.x, -1 * newTri.transform.localScale.y, newTri.transform.localScale.z);
            }

            BadCodeTri2 newTriScript = newTri.GetComponent <BadCodeTri2>();
            newTriScript.myColor   = colors[i];
            newTriScript.myColor.a = 1; //only reason i need to do this is coz i havent looked up how to update new prefabs


            newTriScript.enabled = true;

            //CreateCompositeRBSoChildrenMoveWithParent();

            gameObject.GetComponent <Rigidbody2D>().velocity = birthVelocity;
        }
    }