Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to equip cosmetic materials to player objects?

Discussion in 'Scripting' started by NoSmallTask, Feb 7, 2018.

  1. NoSmallTask

    NoSmallTask

    Joined:
    Aug 5, 2017
    Posts:
    2
    Hello, thanks for taking a look at my post I will try to be brief.

    I have some experience coding with unity and am very fluent with the basics. I have made some very simple games and am ready to take on a more challenging project.

    I am making a game similar to the "How to make a video game" series by Brackeys, however I am making my own twists making it function like a sellable game. Anyway, I'm trying to make a system where you earn currency each time you complete a level than use that currency to buy player cosmetics. I'm stuck on the part of applying the chosen materials. Say, the default color for the player (which is a cube) is green, I earn currency and I buy a blue color. How would I go about applying that? Should I instantiate an instance of the player prefab into each level or should I just make it so the cube doesn't get destroyed on load and customize that.

    The other thing is, either way I do it, how would I go about applying that color to the prefab or the object? So far here is an example of what I tried so far:

    // the player object

    public GameObject playerPrefab;

    // the old and new materials

    Material currentMaterial;

    Material newMaterial;

    // checking what the current material is

    currentMaterial = playerPrefab.GetComponent<renderer>().material;

    //setting the current material to the selected one

    currentMaterial = newMaterial;


    So that's what I have so far, I'm not to worried about the errors that may return (lets just say there are quite a few, however if you could help with that, thanks) but is this the right way to go about this?

    Cheers!