Customizing multi player
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
Something like how you can import $$anonymous$$inecraft skins into the game. This is my first question here so I'm not sure how this works lol
Answer by Statement · Oct 31, 2015 at 06:27 PM
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 { }
Thank you. I can definitely use this, but is there a way a player could make his or her own model in blender or maya and import it in for multiplayer use. If not, the information you gave me will be beneficial for my game
Yes, it's possible. However you need a mechanism for distributing the content to the players. Unity has no built in support for loading non-unity asset files at runtime so you need to parse the model files yourself, or convert it into an asset bundle from a server/service running Unity that can import the model & squeeze out an asset bundle. See also Loading Resources at Runtime
I don't know what 3rd party plugins there are. A quick google for "unity load blender file at runtime" landed me at this plugin via a forum post. I do not promote or endorse this particular asset and can neither recommend you to use it or avoid it. What I mean is that you can find solutions for pretty much anything and this was the first example that popped up. Some of them are free, some of them you have to pay for.
Your answer
Follow this Question
Related Questions
Modifying Unity Network Lobby 0 Answers
Using Transform Component and selfmade interface in an Network Command ? 0 Answers
Networking Pushing 0 Answers