- Home /
how to changes color of the 3rd gameobject by colliding and destroying 1st and 2nd gameobjects
Hi All, Here is the scenario I have 6 different objects which are randomly instantiated every 5 seconds.
suppose say if we drag and collide with the gameobject which having same name "one" i am destroying those two gameobjects and instantiate another gameobject with name "two".
My problem is i have power up in the game in which it changes the color of that gameobject. i want that effect to be transfered to the newly instantiate gamobject when the collision is done as explained above.
it should only transfer when we drag and collide the power up given gameobject. can anyone explain how to proceed with this scenario.
Answer by FirePlantGames · Sep 16, 2016 at 04:45 AM
Set a new GameObject variable as your created objected :) Like so;
public GameObject newEffectedGameObject;
GameObject ourNewObject = (GameObject)Instantiate(newEffectedGameObject, transform.position, transform.rotation);
ourNewObject.GetComponent <Renderer>().material.color = Color.green;
You'll have to modify the code to get it to fit your needs, but you mainly want to focus on the Instantiate part.
@memorymod i don't want the color on every time i Instantiate the gameobject. i need it to be done when the gameobject is effected with power-up and that gameobject is collide with same name gamobject.
here is scenario i will explain i have 4 objects with same name if they collide with each other they are destroyed and Instantiate new object with different name . suppose if we give the power up to gameobject 1 when it is collide with other 3 the new object Instantiate must have same power up effect but if we collide gameobject 2 and 3 it should take color effect of gameobject 1 because it already color effect on it.
i want how to identify that during Instantiate as all the gameobjects posses same script.the newly Instantiate will have different script.
You're seriously giving such a lack of information. What are you struggling with? Since "Write me code" questions aren't allowed in the first place, you're making this even more difficult by not supplying enough information for what you want to achieve.
Explain more clearly and less in a jumbled manner (make a diagram if you have to) What exactly do you want this code to do? What do you want it to detect and how do you want it to react?