Hello guys, this is an edited question. I reread what I originally posted and decided that I need to explain what I need help with better. Okay let me piece this together carefully.
//The black squares are instantiated at start at random from the Top row, to the row just above the Yellow.
//I need the blocks to move down EXACTLY -1.25f on the Y axis. In other words the block will move down 1 space. (They all need to move together).
//Only the black block closest to the yellow will execute this command, the others should not do this until they have reached the y axis of -3.75f.
//The gameobject’s name is “BlackTileClone” with a tag of “BlackTile”
//I send a raycast to mouse position with a if statement of “touchcount > 0”
//I’ve tested various methods like FindGameObjectWithTag and GameObject.name and my results weren’t so good. I tried using a foreach loop and it appears that my -1.25 was multiplied by the number of instantiated blocks. (numBlackBlocks * -1.25).
//I know the answer is right in front of my. I feel as though I’ve stressed myself out to the point that everything is complicated. >.<
Here is the picture of my game.
I have added some code that I feel is very close and precise. I put a lot of effort into commenting out every decision I made.
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
private bool canexecute;
private GameObject[] grabBlackClonesArray;
//We created our bool to determine if the cube is at -3.75f
//We also created the GameObject Array
void Start()
{
//We set the array to have slots 0,1,2,3 (total of 4)
grabBlackClonesArray = new GameObject[3];
//We debug to see if the position 0 is not null
Debug.Log (grabBlackClonesArray[0]);
}
void Update() {
//We finally set grabBlackClonesArray and fill it up with all objects
//with the tag "BlackTile"
grabBlackClonesArray = GameObject.FindGameObjectsWithTag("BlackTile");
//We check to see if it is true
Debug.Log (grabBlackClonesArray[0]);
//To make sure that the movement is only done once we put it in a loop
//remember we are in the Update method..it's called every frame
for(int i = 0; i < 1; i++) {
//With this code the Black Block in slot [1] SHOULD only move EXACTLY
//-1.25f from it's CURRENT location. However this isn't true.
//I get these numbers, far from being exact.
//X:1.657822 Y:-0.6175802 Z:-13.79006
//Also somewhere around here is were we would include our bool
//to check if the block in [1] is in the -3.75 Y position, and if it is it can be executed then moved up top
//in a random vector (Reusing resources)
grabBlackClonesArray [1].transform.position = new Vector3 (transform.position.x, transform.position.y -1.25f , transform.position.z);
}
}
}
It appears as though it’s because my instantiated objects are placed using Random.Range.
The blacktile that I change the vector value of ALWAYS stays in the same place with each
game restart. It is no longer random like it should be.