Need Help For Mini Script ( Change Object Material )

hi guys!
i’m an environment artist and , i dont know anything about script :frowning: :face_with_spiral_eyes:
i need help for script when i click on object , object will change with list of objects,Respectively.
And an example for similar material change.

thank’s :roll_eyes:

Do you mean that when the object is clicked on, it should be replaced by the next object in a list of objects?

yes !
select one and replace with it.

sry about my english :roll_eyes:

For clicking on an object, give the object a collider and use the OnMouseDown() function. As for replacing the object with a new one, I answered a similar question here.

thank Jesse for your helpfull !
but i don’t know anything about scripting :frowning:
can u write a mini script for this ?

sry for this request :frowning:

You’ll have to learn some programming if you want to be able to use Unity effectively. There are plenty of tutorials and references available though that you can use to get started (just search the forums for ‘scripting tutorial’, and you should find some).

Meanwhile, here’s what the code might look like in C# (not compiled or tested):

using UnityEngine;

public class ReplaceOnClick : MonoBehaviour
{
    public GameObject prefab;

    void OnMouseDown()
    {
        GameObject.Instantiate(prefab, transform.position, transform.rotation);
        Destroy(gameObject);
    }
}

(That’s off the top of my head, so I might not have gotten all the details right.)

thank’s Jesse.
i test it , it work :wink:
but ,If I want to act as a rotating between several object what should I do?

Using the above script (or one like it), you could create a set of prefabs, each of which references another prefab in the set. For example, for three prefabs A, B, and C, A would reference B, B would reference C, and C would reference A. Then, clicking on the objects would result in cycling through the object types.

(There are other options, but that’s probably the most straightforward solution.)

thank’s jesse.
i use it , it work with several object :wink:
you are my script hero :smile: