Hi,
I am working on 2D game in unity 4.3. I have a single red and blue ball and I want to create their clones on runtime and adding into different array with different tag but what happen when I try to assign tag then its break loop and just run code on above of assigning tag code.
Below is my code to create 5 5 red and blue balls.
int i =0;
int tag=1;
float differenceX = 0.25f;
float differenceY = 0.25f;
while(i<5){
Vector3 position = new Vector3(blueBall.transform.position.x+differenceX,blueBall.transform.position.y,blueBall.transform.position.z);
GameObject redBall1 = Instantiate(redBall,position,Quaternion.identity) as GameObject;
tag = tag+i;
redBall1.gameObject.tag = "RedBall"+tag;
Vector3 positionBlue = new Vector3(blueBall.transform.position.x+differenceX,blueBall.transform.position.y-differenceY,blueBall.transform.position.z);
GameObject blueBall1 = Instantiate(blueBall,positionBlue,Quaternion.identity) as GameObject;
blueBall1.gameObject.tag = "BlueBall"+tag;
redBallsArray *= redBall1;*
_ blueBallsArray = blueBall1;_
* differenceX =differenceX+0.25f;*
* i++;*
* }*
Code break from “redBall1.gameObject.tag = “RedBall”+tag;” and not execute code after that and when I block this line then it works fine and create all ball otherwise its just show only only one ball.
I also tried with “blueBall1.transform.tag” and “blueBall1.tag”. Kindly tell me any other approach to assigning tag or other technique to store each object with different identity in array. Thanks in advance.