using UnityEngine;
using System.Collections;
namespace TNet
{
/// <summary>
/// Instantiate the specified prefab at the game object's position.
/// </summary>
public class TNAutoCreatePlayer : TNBehaviour
{
public static Manager manager_instance;
/// <summary>
/// ID of the channel where the prefab should be created. '0' means "last used channel".
/// </summary>
public int channelID = 0;
/// <summary>
/// Prefabs to instantiate.
/// </summary>
string playerprefabPath;
string charactertype;
/// <summary>
/// Whether the instantiated object will remain in the game when the player that created it leaves.
/// Set this to 'false' for the player's avatar.
/// </summary>
public bool persistent = false;
void Awake (){
charactertype = PlayerPrefs.GetString ("charactertype");
manager_instance = GameObject.FindGameObjectWithTag ("manager").GetComponent<Manager>();
}
IEnumerator Start ()
{
while (TNManager.isJoiningChannel) yield return null;
if (charactertype == "1")
playerprefabPath = "petmaster_world";
if (charactertype == "2")
playerprefabPath = "champion_world";
if (charactertype == "3")
playerprefabPath = "mystic_world";
if (channelID < 1) channelID = TNManager.lastChannelID;
TNManager.Instantiate(channelID, "CreatePlayer", playerprefabPath, persistent, transform.position, transform.rotation);
Destroy(gameObject);
}
[RCC]
static GameObject CreatePlayer (GameObject prefab, Vector3 pos, Quaternion rot)
{
// Instantiate the prefab
GameObject go = prefab.Instantiate();
// Set the position and rotation based on the passed values
Transform t = go.transform;
t.position = pos;
t.rotation = rot;
go.name = "player" + TNManager.playerID; // The name of the gameobject is the same for each player that joins
return go;
}
}
}