How to make bullet prefab take color of the character?

Okay, so I’m using a bullet prefab for the shooting. The bullet prefab is attached to my characters (both player and enemies), which shoot it out of their bodies. My characters get a random color for their body thanks to this script:

using UnityEngine;
using System.Collections;

public class ColorChanger : MonoBehaviour {
	void Start() {
		RandomColor();
	}
	
	public void RandomColor() {
		GetComponent<SkinnedMeshRenderer>().material.color = new Color(Random.value, Random.value, Random.value);
	}
}

I want the bullet prefab they shoot to have the same color as the characters that shoot it (if that’s possible). So, pretty please, tell me if such a thing is possible and if so how could I do it. Please be specific because I’m a noob and if you have a simple script I could use, I would be eternally grateful.

Well it looks like you’re setting the colour of the player successfully, so doing so to the bullet will be by essentially the same process. The main thing is that you’ll need to save the colour that you get when you set the player’s. If you declare it as a variable then you will be able to assign it to the bullet later. First:

 using UnityEngine;
 using System.Collections;
 
 public class ColorChanger : MonoBehaviour
{
    public Color playerColor;
    
    void Start()
    {
        RandomColor();
    }
     
     public void RandomColor()
    {
         playerColor = new Color(Random.value, Random.value, Random.value);
         GetComponent<SkinnedMeshRenderer>().material.color = playerColor;
    }
 }

Then you’ll have to do something along these lines:

//Somewhere in your shooting script...

void Shoot()
{
    var bullet = GameObject.Instantiate(bulletPrefab, player.transform.location, Quaternion.identity);
    bullet.GetComponent<SkinnedMeshRenderer>().material.color = playerColorFromTheColorChangerScript;
    //And so on...
}

I’m going to assume you know how to access variables from other scripts, but if you need help with that just leave a comment.

Hope this helps!