/** * Creates a player with the given settings at the given position */ public GameObject CreatePlayer(Vector3 pos, PlayerSettings settings) { // Create the player GameObject player = Instantiate(prefab, pos, Quaternion.identity); PlayerLimbs limbs = player.GetComponent <PlayerLimbs> (); // Setting the player customisation using player limbs GameObject hat = skins.hats [settings.indices.hatIndex]; GameObject playerHat = Instantiate(hat, limbs.head.transform.position, limbs.head.transform.rotation); playerHat.transform.parent = limbs.head.transform; Mesh lance = skins.lances [settings.indices.lanceIndex].GetComponentInChildren <MeshFilter>().sharedMesh; Mesh playerLance = Instantiate(lance); limbs.lance.GetComponent <MeshFilter> ().sharedMesh = playerLance; player.GetComponent <PlayerLimbs> ().character.GetComponent <Renderer> ().material = skins.outfits [settings.indices.outfitIndex]; PlayerInput input = new InputKeyboard(); switch (settings.input) { case InputType.Keyboard: input = new InputKeyboard(); (input as InputKeyboard).RefreshInputs(settings.keyboardID); break; case InputType.Mouse: input = new InputMouse(); break; case InputType.Controller: input = new InputController(); (input as InputController).RefreshInputs(settings.controllerID); break; } // Tell the movement script to add the appropriate input type PlayerMovement m = player.GetComponentInChildren <PlayerMovement>(); m.SetInput(input); m.settings = settings; //CurrentPrefab.GetComponentInChildren<SetMaterial>().setMat(newMat); return(player); }
/** * makes a ragdoll and unparents the lance and chair **/ protected GameObject RagDoll(GameObject playerHit) { // The top level of the player prefab, this ensures we are dealing with the parent object everytime Transform parent = playerHit.transform.root; // get the wrapper as this has the chair and material as chidlren Transform wrapper = parent.transform.Find("wrapper"); // deparent the lance GameObject lance = playerHit.GetComponentInChildren <PlayerHitDetection> ().gameObject; Destroy(lance.GetComponent <PlayerHitDetection> ()); lance.transform.parent = null; lance.AddComponent <Rigidbody> (); // unparent the chair Transform chair = wrapper.Find("chairA"); chair.parent = null; chair.gameObject.AddComponent <Rigidbody> (); // get the material Material ragdollMat = wrapper.Find("PlayerModel").GetComponent <Renderer> ().material; // create the ragdoll, position it and apply the material //Quaternion q = Quaternion.Euler(-parent.transform.forward); GameObject ragDoll = (GameObject)Instantiate(Resources.Load("Ragdoll - final"), parent.transform.position, parent.transform.rotation); //ragDoll.transform.rotation = Quaternion.Euler (parent.transform.rotation.eulerAngles); ragDoll.GetComponentInChildren <Renderer> ().materials = new Material[] { ragdollMat, ragdollMat }; PlayerLimbs limbs = ragDoll.GetComponent <PlayerLimbs> (); // Setting the player customisation using player limbs GameObject hat = parent.GetComponentInChildren <Hat> ().gameObject; //GameObject playerHat = Instantiate (hat, limbs.head.transform.position, limbs.head.transform.rotation); hat.transform.position = limbs.head.transform.position; hat.transform.rotation = limbs.head.transform.rotation; hat.transform.parent = limbs.head.transform; // destroy the old payer model Destroy(parent.gameObject); return(ragDoll); }