Advertisement
Guest User

Untitled

a guest
Sep 21st, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.19 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CreateCharacter : MonoBehaviour
  5. {
  6.  
  7. public GUISkin g; //Default GUISkin
  8. public GUISkin finalSkin; //Good-looking GUISkin
  9.  
  10. int page; //Variable for different pages of Main Menu
  11. public GameObject createVik; //Prefab for Vikings' race
  12. GameObject axe; //Different variables for vikings' race. First weapons for different classes and description to the whole race
  13. GameObject shield;
  14. GameObject axe2;
  15. GameObject bigAxe;
  16. string vik_desc = "These guys are brave, strong and bold. Vikings have a great history. And now they must save the world!";
  17.  
  18. public GameObject createGOB; //Prefab for Vikings' race
  19. GameObject axeG; //Different variables for vikings' race. First weapons for different classes and description to the whole race
  20. GameObject shieldG;
  21. GameObject axe2G;
  22. GameObject bigAxeG;
  23. string vik_descG = "These guys are brave, strong and bold. Vikings have a great history. And now they must save the world!";
  24. /* There you can add your own prefabs and race's variables for different races
  25. public GameObject createYourRace;
  26. ...
  27. */
  28.  
  29. bool oCreate; //It is for Instantiate. We need it only one time.
  30. GameObject hero; //Hero
  31. string game_name; //Hero's name
  32. string game_class; //Hero's class
  33. string game_race; //viking race
  34. string game_race2; //orc race
  35. string class_desc; //Desription for hero's class
  36. string race_desc; //Desription for hero's race
  37. string warrior_desc = "Warriors always have a powerful two-handled weapon and great strength. Warrior is a good choice for assured players.";
  38. string defender_desc = "Defenders think a little bit before start a new battle. They have shield and one-handled weapon. Defender is an excellent class for clever and logical players.";
  39. string robber_desc = "Robbers are fast, quiet and invisible. They use two one-handled weapons. Robber is a great choice for wise men.";
  40.  
  41. // For errors
  42. bool erGUI1;
  43. bool erGUI2;
  44.  
  45. void Awake()
  46. {
  47. game_name="Name"; //Default name is "Name"
  48. }
  49.  
  50. public void AnswerCreate(string ans){
  51. if(ans=="Created"){
  52. Application.LoadLevel("ChooseCharacter"); //Creation will be successful only if character's name is unique and Player has already two characters or less
  53. }else{
  54. if(ans == "Been"){
  55. StartCoroutine("ErrorWindow", "alreadyBeen"); //Error if this name has already been
  56. }
  57. if(ans == "TooMuch"){
  58. StartCoroutine("ErrorWindow", "tooMuch"); //Error if Player has three characters in one account
  59. }
  60. }
  61. }
  62.  
  63. void OnGUI()
  64. {
  65. GUI.skin=finalSkin;
  66. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////CREATE CHARACTER
  67. GUILayout.BeginArea(new Rect(Screen.width / 2.5f, 50, 400, 1000));
  68. GUILayout.Label("\t\t\tCreating character", "LargeTextChoose");
  69. if(oCreate==false){
  70. hero = GameObject.Instantiate(createVik, new Vector3(70.80774f,4.55112f, 65.6056f), Quaternion.identity) as GameObject;
  71. hero.transform.Rotate(1.253711f,228.0281f,1.257576f);
  72. game_class="Warrior";
  73. game_race="Viking";
  74. game_race2="GOBLIN";
  75. race_desc=vik_desc;
  76. class_desc=warrior_desc;
  77. MeshRenderer[] rens = GameObject.Find("Player(Clone)").GetComponentsInChildren<MeshRenderer>();
  78. if(game_race=="Viking"){
  79. hero = GameObject.Instantiate(createVik, new Vector3(70.80774f,4.55112f, 65.6056f), Quaternion.identity) as GameObject;
  80. hero.transform.Rotate(1.253711f,228.0281f,1.257576f);
  81. axe = GameObject.Find("Player(Clone)/Viking/CATRigHub001/CATRigSpineCATRigSpine1/CATRigSpine2/CATRigHub002/CATRigLArmCollarbone/CATRigLArm1/CATRigLArm2/CATRigLArmPalm/Axe") as GameObject;
  82. bigAxe = GameObject.Find("Player(Clone)/Viking/CATRigHub001/CATRigSpineCATRigSpine1/CATRigSpine2/CATRigHub002/CATRigLArmCollarbone/CATRigLArm1/CATRigLArm2/CATRigLArmPalm/Big Axe") as GameObject;
  83. axe2 = GameObject.Find("Player(Clone)/Viking/CATRigHub001/CATRigSpineCATRigSpine1/CATRigSpine2/CATRigHub002/CATRigRArmCollarbone/CATRigRArm1/CATRigRArm2/CATRigRArmPalm/Axe") as GameObject;
  84. shield = GameObject.Find("Player(Clone)/Viking/CATRigHub001/CATRigSpineCATRigSpine1/CATRigSpine2/CATRigHub002/CATRigRArmCollarbone/CATRigRArm1/CATRigRArm2/CATRigRArmPalm/Shield") as GameObject;
  85. axe.SetActive(false);
  86. shield.SetActive(false);
  87. axe2.SetActive(false);
  88. foreach(MeshRenderer m in rens){
  89. if(m.gameObject.name!=axe.name && m.gameObject.name!=axe2.name && m.gameObject.name!=bigAxe.name && m.gameObject.name!=shield.name){
  90. m.gameObject.SetActive(false);
  91. }
  92. }
  93. }
  94. if(game_race=="GOBLIN"){
  95. hero = GameObject.Instantiate(createGOB, new Vector3(70.80774f,4.55112f, 65.6056f), Quaternion.identity) as GameObject;
  96. hero.transform.Rotate(1.253711f,228.0281f,1.257576f);
  97. axe = GameObject.Find("Player(Clone)/GOBLIN/rig/GOB_one_Sword/Bone_Axe") as GameObject;
  98. bigAxe = GameObject.Find("Player(Clone)/GOBLIN/rig/GOB_one_Sword/Bone_Axe") as GameObject;
  99. axe2 = GameObject.Find("Player(Clone)/GOBLIN/rig/GOB_one_Sword/Bone_Axe") as GameObject;
  100. shield = GameObject.Find("Player(Clone)/GOBLIN/rig/GOB_Shield/Bone_Shield") as GameObject;
  101. axe.SetActive(false);
  102. shield.SetActive(false);
  103. axe2.SetActive(false);
  104. foreach(MeshRenderer m in rens){
  105. if(m.gameObject.name!=axe.name && m.gameObject.name!=axe2.name && m.gameObject.name!=bigAxe.name && m.gameObject.name!=shield.name){
  106. m.gameObject.SetActive(false);
  107. }
  108. }
  109. }
  110. /* There you can add properties to your own race
  111. if(game_race=="your_race"){
  112.  
  113. }*/
  114.  
  115. oCreate=true;
  116. }
  117. GUILayout.EndArea();
  118. GUI.Box(new Rect(Screen.width / 2.5f-30, Screen.height-55, 340,60), "", "Window2");
  119. if(GUI.RepeatButton(new Rect(Screen.width / 2.5f-10, Screen.height-40, 50,40), "<")){
  120. hero.transform.Rotate(0,1,0);
  121. }
  122. game_name = GUI.TextField(new Rect(Screen.width / 2.5f+40, Screen.height-35, 200,30), game_name);
  123. if(GUI.RepeatButton(new Rect(Screen.width / 2.5f+40+200, Screen.height-40, 50,40), ">")){
  124. hero.transform.Rotate(0,-1,0);
  125. }
  126. GUI.Box(new Rect(-10,-25,Screen.width/4+40,Screen.height/2+50), "", "Window");
  127. GUI.Label(new Rect(30,5,Screen.width/4-40,30), "Classes:");
  128. if(GUI.Button(new Rect(20,60,Screen.width/4-20,(Screen.height/2)/5), "Warrior")){
  129. game_class="Warrior";
  130. shield.SetActive(false);
  131. axe.SetActive(false);
  132. bigAxe.SetActive(true);
  133. axe2.SetActive(false);
  134. class_desc=warrior_desc;
  135. }
  136. if(GUI.Button(new Rect(20,60+(Screen.height/2)/5,Screen.width/4-20,(Screen.height/2)/5), "Defender")){
  137. game_class="Defender";
  138. shield.SetActive(true);
  139. axe.SetActive(true);
  140. bigAxe.SetActive(false);
  141. axe2.SetActive(false);
  142. class_desc=defender_desc;
  143. }
  144. if(GUI.Button(new Rect(20,60+((Screen.height/2)/5)*2,Screen.width/4-20,(Screen.height/2)/5), "Robber")){
  145. game_class="Robber";
  146. shield.SetActive(false);
  147. axe.SetActive(true);
  148. bigAxe.SetActive(false);
  149. axe2.SetActive(true);
  150. class_desc=robber_desc;
  151. }
  152. GUI.Box(new Rect(-10,Screen.height/2-24,Screen.width/4+40,Screen.height/2+50), "", "Window");
  153. GUI.Label(new Rect(30,Screen.height/2+6,Screen.width/4-40,30), "Description:");
  154. GUI.TextArea(new Rect(20,Screen.height/2+70, Screen.width/4-20,(Screen.height/2)-100),class_desc);
  155. GUI.Box(new Rect(Screen.width-Screen.width/4-30,-25,Screen.width/4+40,Screen.height/2+50), "", "Window");
  156. GUI.Label(new Rect(Screen.width-Screen.width/4+10,5,Screen.width/4-40,30), "Race:");
  157. if(GUI.Button(new Rect(Screen.width-Screen.width/4,60,Screen.width/4-20,(Screen.height/2)/5), "Viking")){
  158. game_race="Viking";
  159. }
  160. if(GUI.Button(new Rect(Screen.width-Screen.width/4,120,Screen.width/4-20,(Screen.height/2)/5), "Orc")){
  161. game_race="orc";
  162. }
  163. GUI.Box(new Rect(Screen.width-Screen.width/4-30,Screen.height/2-24,Screen.width/4+40,Screen.height/2+10), "", "Window");
  164. GUI.Label(new Rect(Screen.width-Screen.width/4+10,Screen.height/2+6,Screen.width/4-40,30), "Description:");
  165. GUI.TextArea(new Rect(Screen.width-Screen.width/4,Screen.height/2+71, Screen.width/4-20,(Screen.height/2-40)-100 ),race_desc);
  166. if(GUI.Button(new Rect(Screen.width-Screen.width/4, Screen.height-30, Screen.width/4, 25), "Create!")){
  167. GameObject.Find("INFO").GetComponent("INFO").SendMessage("GetInfo", game_name+":"+game_race+":"+game_class+":1:0:Nothing:0:Nothing:Nothing:Nothing:Nothing");
  168. //PlayerPrefs.SetInt(INFO.ReturnEmail()+"_"+INFO.ReturnName()+"_Spell0", 1);
  169. //PlayerPrefs.SetInt(INFO.ReturnEmail()+"_"+INFO.ReturnName()+"_Spell1", 2);
  170. }
  171. ////////////////////////////////////ERRORS
  172. GUI.skin = g;
  173. if(erGUI1==true){
  174. GUI.Box(new Rect(Screen.width/3,Screen.height/2.5f,Screen.width/3,30), "This name is already taken!");
  175. }
  176. if(erGUI2==true){
  177. GUI.Box(new Rect(Screen.width/3,Screen.height/2.5f,Screen.width/3,30), "You can create only 3 characters!");
  178. }
  179. }
  180.  
  181. IEnumerator ErrorWindow (string er){
  182. if(er=="alreadyBeen"){
  183. erGUI1=true;
  184. yield return new WaitForSeconds(2);
  185. erGUI1=false;
  186. }
  187. if(er=="tooMuch"){
  188. erGUI2=true;
  189. yield return new WaitForSeconds(2);
  190. erGUI2=false;
  191. }
  192. }
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement