Hi my game is both single and multi player. I have separate models for my single player but for online gameplay I want to give the ability to players to create their own avatars. They can either use what I give them or upload their own from something like maya or blender. How would I make this possible. I’ve finished the single player but this multi player stuff is new to me. Thx
Welcome. Please try to ask one question per thread. Googling for minecraft skins told me they were located at http://skins.minecraft.net/MinecraftSkins/<USERNAME>.png
.
Here’s an example of a script that downloads a skin for a particular user and optionally sets the texture of the renderers material to that texture.
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Events;
public class DownloadMinecraftSkin : MonoBehaviour
{
public string username = "Statement";
public bool applySkinToRenderer = true;
public Texture2DEvent onDownloaded;
public ErrorEvent onError;
[HideInInspector]
public Texture2D skin;
const string urlformat = "http://skins.minecraft.net/MinecraftSkins/{0}.png";
public string url { get { return string.Format(urlformat, username); } }
IEnumerator Start()
{
using (WWW www = new WWW(url))
{
yield return www;
if (string.IsNullOrEmpty(www.error))
OnDownloaded(www.textureNonReadable);
else
OnError(www.error);
}
}
void OnDownloaded(Texture2D skin)
{
if (applySkinToRenderer)
{
Renderer renderer = GetComponent<Renderer>();
if (renderer && renderer.sharedMaterial)
renderer.material.mainTexture = skin;
else
Debug.LogError("Missing renderer or material", this);
}
onDownloaded.Invoke(skin);
}
void OnError(string error)
{
Debug.LogErrorFormat(this, "Downloading minecraft skin '{0}' failed: '{1}'", username, error);
onError.Invoke();
}
}
[Serializable]
public class Texture2DEvent : UnityEvent<Texture2D> { }
[Serializable]
public class ErrorEvent : UnityEvent { }