- Home /
Change object's clone tag after creation.
Hi, I am working on 2D game in Unity 4.3. In this game I have to create multiple balls on runtime so I think I need to make clone of these ball. My app has following specification.
I have four type of ball differentiate by different colors.
Single Ball send by swipe one by one in main scene (where few types ball already there).
When same type of ball collide then these same ball will destroy.
Ball quantity will be unlimited until user fill the scene. So what I want to create clone on runtime so that I can create ball as I want, so thats why I think I need to use clone approach If there will be different and better approach so kindly suggest me because I am new bee in Unity 3D. I am swiping with the help of tag so I want when I sent ball toward scene then I create clone of this ball and change sent ball's tag name so that I can differentiate sent and to be send ball. I tried but I can do this. I am doing this on OnEnterCollision2D Method but this is not working.
void OnCollisionEnter2D(Collision2D coll) { if(coll.gameObject.name=="Boundry"){ Instantiate(this,currentBallPosition,Quaternion.identity); this.tag=@"sentblue1"; }
Kindly help me on this. And also suggest me better approach to do this task. Thanks in advance this will be great for me.
Can you explain what is not working? Assu$$anonymous$$g you are trying to change the tag on the current game object, I'd do it this way:
Instantiate(gameObject,currentBallPosition,Quaternion.identity);
gameObject.tag="sentblue1";
But I don't think this will fix your problem.
Your title suggests you are looking for something different. $$anonymous$$aybe:
GameObject go = Instantiate(gameObject,currentBallPosition,Quaternion.identity) as GameObject;
go.tag = "ADifferentTag";
This doesn't work. I'm not sure why though. I think these two answers contradict each other. since once creates a new go the other maybe does but there's no object to refer too.
Your answer
Follow this Question
Related Questions
Set images according to their size in Unity4.3 for 2D game Development 1 Answer
2D object flickers when it is in high speed in Unity 4.3 0 Answers
2D object flickers on moving Unity 4.3 2 Answers
Pull and Push spring on finger moving. 1 Answer
How to set game scene according to iPad and iPhone for 2D game in Unity4.3 1 Answer