D
D
Denis Mashanov2017-03-04 08:13:33
Unity
Denis Mashanov, 2017-03-04 08:13:33

Why does changing the properties of one object change those of others?

Good afternoon everyone. Help me solve the problem please.
When I create objects in the scene by loading a prefab from a resource, it turns out that when I change the property of one object, the others also change. How to decide?
list - an array of coordinates

foreach (int[] pos in list)
        {
            GameObject objectfield = Resources.Load<GameObject>("object");
            objectfield.name = pos[0].ToString() + pos[1].ToString() + "object";
            objectfield.transform.position = new Vector3(pos[0], 0, pos[1]);
            Instantiate(objectfield);
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Mashanov, 2017-03-04
@LoneRay

Problem solved.

foreach (int[] pos in list)
        {
            Material shell = new Material(Resources.Load<Material>("material"));
            GameObject objectfield = Instantiate(Resources.Load<GameObject>("object"));
            objectfield.name = pos[0].ToString() + pos[1].ToString() + "object";
            objectfield.transform.position = new Vector3(pos[0], 0, pos[1]);
            objectfield.GetComponent<Renderer>().material = shell;
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question