Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.25 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using UnityEngine.Networking;
  7.  
  8. public class NaturalMovementPlatforming : NetworkBehaviour
  9. {
  10. [SerializeField]
  11. private GameObject bulletPrefab;
  12. [SerializeField]
  13. private GameObject ShotgunBulletPrefab;
  14. [SerializeField]
  15. private GameObject CompassBulletPrefab;
  16. [SerializeField]
  17. private GameObject WeakBulletPrefab;
  18. [SerializeField]
  19. private GameObject bulletSpawn;
  20. [SerializeField]
  21. private GameObject bulletSpawn2;
  22. [SerializeField]
  23. private Camera camera;
  24. [SerializeField]
  25. private GameObject rotationChecker;
  26. private bool fly = false;
  27. private bool parry = false;
  28.  
  29. [SerializeField]
  30. private GameObject waterCameras;
  31. [SerializeField]
  32. private GameObject playerCamera;
  33.  
  34. [Header("Movement")]
  35. [SerializeField]
  36. private float _acceleration;
  37. [SerializeField]
  38. private float _maxAcceleration;
  39. [SerializeField]
  40. private float _maxVelocity;
  41.  
  42. [Header("MoveSpeed")]
  43. [SerializeField]
  44. private float _speed;
  45. bool isGround = false;
  46.  
  47. [Header("Jumping")]
  48. [SerializeField]
  49. private float _groundedDistance;
  50. [SerializeField]
  51. private float _jumpVelocity;
  52. [SerializeField]
  53. private float _jumpCooldown;
  54. //[SerializeField]
  55. //private bool Touching = false;
  56. [SerializeField]
  57. private float _hangtime;
  58.  
  59. private Rigidbody _rigidbody3d;
  60. private float _jumpTimer;
  61. private Vector3 goForward = new Vector3(0,0,1);
  62.  
  63. private Vector3 rotateValue;
  64. private float y;
  65. private float x;
  66. [Header("Sensitivity")]
  67. [SerializeField]
  68. private float sensitivity;
  69. [SerializeField]
  70. private GameObject canvas;
  71.  
  72. [SerializeField]
  73. private Text AmmoText;
  74. [SerializeField]
  75. private Text AmmoText2;
  76. [SerializeField]
  77. private Text AmmoText3;
  78.  
  79. [SerializeField]
  80. private Texture2D crosshair;
  81. [SerializeField]
  82. private Text items;
  83. [SerializeField]
  84. private Text book;
  85. [SerializeField]
  86. private AudioListener listener;
  87. private int Line_of_the_username_in_the_file = 0;
  88.  
  89. [Header("Models")]
  90. [SerializeField]
  91. private GameObject MeshCharacterA;
  92. [SerializeField]
  93. private GameObject demoMesh;
  94. [SerializeField]
  95. private GameObject lifeGemNOTcritboxGem;
  96.  
  97. private bool Save_and_quit = false;
  98. private int numPlayers = 0;
  99. private Rect position;
  100. private float waitTime;
  101. private float waitTime2;
  102. private float waitTime3;
  103. private float waitTime4;
  104. public static string[] playerSize2 = new string[20];
  105. private bool pointless = true;
  106. private static string[] cards = new string[20];
  107. private static string[] newCards = new string[20];
  108. private static GameObject[] Allplayers = new GameObject[10000]; //just a random number here...Max 10000 players?
  109. private string first;
  110. private bool isSpellCasting = false;
  111.  
  112. //[SyncVar(hook = "MakeLarge")]
  113. [SyncVar]
  114. private bool large = true;
  115. //[SyncVar(hook = "MakeSmall")]
  116. [SyncVar]
  117. private bool small = true;
  118. //private LinkedList<string> cards = new LinkedList<string>();
  119. NetworkAnimator m_Animator;
  120. private Animator The_animator;
  121. [SyncVar]
  122. private bool isWalk = false;
  123. [SyncVar(hook = "OnPlayerEntered")]
  124. private int someoneEntered = 0;
  125. [SyncVar]//A VARIABLE UNIQUE TO THE GAMEOBJECT THIS SCRIPT IS ATTACHED TO THAT GETS SYNC'ED ACROSS ALL CLIENTS -- BUT DOES NOT CHANGE VALUE IN THOSE CLIENTS
  126. //private bool
  127.  
  128. private bool isInGame = false;//NEED A WAY TO CHECK WHO IS IN GAME AND WHO IS AT THE MENU -> Easiest way currently is have a 3D world as the literal menu and collision boxes as the choices
  129. //Make the UI Choices all if statements that triggers on collider -> The main menu itself is like an MMO town. To play 'the PVP game' you walk into a collider.
  130. //IT IS CURRENTLY CHECKING USERNAME AND PASSWORD -- THEREFORE IT IS A WORKING "MMO"
  131. //Make it so the 'lobby' is perhaps below -2000 while the main 'battleground' is above... so that you can check the y coordinate below a number for is lobby or is in game
  132.  
  133. private void Awake()
  134. {
  135. _rigidbody3d = GetComponent<Rigidbody>();
  136. Cursor.lockState = CursorLockMode.Locked;
  137. sensitivity = -1.5f;
  138. waitTime2 = Time.time + 1;
  139.  
  140. for(int i = 0; i < cards.Length; i++){
  141. cards [i] = i.ToString();
  142. }
  143.  
  144. book.text = "{ [" + cards[0] + "],[" + cards[1] + "],[" + cards[2] + "],[" + cards[3] + "],[" + cards[4] + "] }";
  145. }
  146.  
  147. [Command]
  148. void CmdDebug(string toPrintThis){
  149. print(toPrintThis);
  150. }
  151.  
  152. /*//check to see if the player is in contact with the ground, works on slopes too!
  153. //as long as the player collides with the ground then isGround is true
  154. void OnCollisionStay(Collision hit)
  155. {
  156. if (hit.gameObject.tag == "ground") {
  157. isGround = true;
  158. }
  159. }
  160.  
  161. //when stop colliding with ground give 0.2 sec hang time
  162. void OnCollisionExit(Collision hit)
  163. {
  164. if (hit.gameObject.tag == "ground")
  165. {
  166. StartCoroutine(notcollidingwithGround());
  167. }
  168. }
  169.  
  170. //some platformer hangtime, even after not colliding with the ground there is a 0.2 second window to jump (this is too generous, change sometime?s)
  171. IEnumerator notcollidingwithGround(){
  172. yield return new WaitForSeconds (_hangtime);
  173. isGround = false;
  174. }*/
  175. int index = 0;
  176. bool lerp = false;
  177.  
  178. void OnTriggerEnter(Collider other){
  179. if (other.tag == "save_and_quit") {
  180. Save_and_quit = true;
  181. } else {
  182. Save_and_quit = false;
  183. }
  184.  
  185. //---------------------------------------------------------
  186. //MAIN MENU
  187. if (other.name == "Play_Collider") {
  188. gameObject.transform.position = new Vector3 (0, 10, 110);
  189. }
  190. //---------------------------------------------------------
  191.  
  192.  
  193. //---------------------------------------------------------
  194. //CHARACTER SELECTION
  195. if (other.name == "Red_Character") {
  196. small = false;
  197. MakeSmall (true); //the true actually does nothing...
  198. CmdMeshSmall ();
  199. CmdUpdateMeshSmall ();
  200. gameObject.transform.position = new Vector3 (0, 10, 204);
  201. }
  202.  
  203. if (other.name == "Blue_Character") {
  204. large = false;
  205. gameObject.transform.position = new Vector3 (0, 10, 204);
  206. }
  207. //---------------------------------------------------------
  208.  
  209.  
  210. //---------------------------------------------------------
  211. //ARENA SELECTION
  212. if (other.name == "Circle_Arena") {
  213. gameObject.transform.position = new Vector3 (1987, 70, 1114);
  214. }
  215. //---------------------------------------------------------
  216.  
  217. if (other.name == "Entered_Battlefield") { //Need to do this for ALL players in battlefield
  218. someoneEntered += 1;
  219. OnPlayerEntered (1);
  220. }
  221.  
  222.  
  223.  
  224. if (other.tag == "fall_off") {
  225. //communicate through UI that someone fell
  226. gameObject.transform.position = new Vector3(1987, 70, 1114); //respawns them
  227. }
  228.  
  229.  
  230. for (int i = 0; i < Health.players.Length; i++) {
  231. if (Health.players [i] == (gameObject.GetComponent<NetworkIdentity> ().netId).ToString()) {
  232. index = i;
  233. }
  234. }
  235.  
  236. if (other.tag == "s_ammo") {
  237. Health.small_ammo[index] += 30;
  238. AmmoText.text = "S" + Health.small_ammo[index].ToString();
  239. } else if (other.tag == "m_ammo") {
  240. Health.medium_ammo[index] += 10;
  241. AmmoText2.text = "M" + Health.medium_ammo[index].ToString();
  242. } else if (other.tag == "l_ammo") {
  243. Health.large_ammo[index] += 3;
  244. AmmoText3.text = "L" + Health.large_ammo[index].ToString();
  245. }
  246. }
  247.  
  248. void OnGUI() {
  249. GUI.DrawTexture (position, crosshair);
  250. }
  251.  
  252. private string[] activeItem = Health.item0;
  253.  
  254. [Command]
  255. void CmdMeshLarge(){
  256. large = false;
  257. //gameObject.tag = "large";
  258. RpcLarge ();
  259. }
  260.  
  261. [Command]
  262. void CmdUpdateMeshLarge(){
  263. gameObject.GetComponent<MeshRenderer> ().enabled = false;
  264. demoMesh.SetActive(true); //make people see large mesh as your character
  265. //gameObject.tag = "large";
  266. RpcSendLarge();
  267. }
  268.  
  269. [Command]
  270. void CmdRemoveMeshLarge(){
  271. demoMesh.SetActive(false); //make people see large mesh as your character
  272. RpcSendRemovedLarge();
  273. }
  274.  
  275. [ClientRpc]
  276. void RpcSendLarge(){
  277. gameObject.GetComponent<MeshRenderer> ().enabled = false;
  278. demoMesh.SetActive(true); //make people see large mesh as your character
  279. //gameObject.tag = "large";
  280. }
  281.  
  282. [ClientRpc]
  283. void RpcSendRemovedLarge(){
  284. demoMesh.SetActive(false); //make people see large mesh as your character
  285. }
  286.  
  287. [ClientRpc]
  288. void RpcSendSmall(){
  289. gameObject.GetComponent<MeshRenderer> ().enabled = false;
  290. MeshCharacterA.SetActive(true); //make people see large mesh as your character
  291. m_Animator = MeshCharacterA.GetComponent<NetworkAnimator>();
  292. The_animator = MeshCharacterA.GetComponent<Animator> ();
  293. m_Animator.SetParameterAutoSend (0, true);
  294. gameObject.tag = "small";
  295. }
  296.  
  297. [ClientRpc]
  298. void RpcSendRemovedSmall(){
  299. gameObject.GetComponent<MeshRenderer> ().enabled = false;
  300. MeshCharacterA.SetActive(true); //make people see large mesh as your character
  301. m_Animator = MeshCharacterA.GetComponent<NetworkAnimator>();
  302. The_animator = MeshCharacterA.GetComponent<Animator> ();
  303. m_Animator.SetParameterAutoSend (0, true);
  304. }
  305.  
  306. [Command]
  307. void CmdUpdateMeshSmall(){
  308. //Allplayers = UnityEngine.Object.FindObjectsOfType<GameObject>();
  309. //for (int i_i = 0; i_i < Allplayers.Length; i_i++) {
  310. // if(Allplayers[i_i].tag == "small"){
  311. gameObject.GetComponent<MeshRenderer> ().enabled = false;
  312. MeshCharacterA.SetActive(true); //make people see large mesh as your character
  313. m_Animator = MeshCharacterA.GetComponent<NetworkAnimator>();
  314. The_animator = MeshCharacterA.GetComponent<Animator> ();
  315. m_Animator.SetParameterAutoSend (0, true);
  316. gameObject.tag = "small";
  317. RpcSendSmall();
  318. // }
  319. //}
  320. }
  321.  
  322. /* [Command]
  323. void CmdRemoveMeshSmall(){
  324. gameObject.GetComponent<MeshRenderer> ().enabled = false;
  325. MeshCharacterA.SetActive(true); //make people see characterA mesh as your character
  326. RpcSendRemovedSmall();
  327. }*/
  328.  
  329. void MakeLarge(bool visibility){
  330. //Debug.Log (visibility);
  331. gameObject.GetComponent<MeshRenderer> ().enabled = false;
  332. demoMesh.SetActive(true); //make people see large mesh as your character
  333. camera.transform.position = camera.transform.position + new Vector3(0,1,-1);
  334. }
  335.  
  336. [ClientRpc]
  337. void RpcLarge(){
  338. gameObject.GetComponent<MeshRenderer> ().enabled = false;
  339. demoMesh.SetActive(true); //make people see large mesh as your character
  340. //gameObject.tag = "large";
  341. }
  342.  
  343. [Command]
  344. void CmdMeshSmall(){
  345. //Allplayers = UnityEngine.Object.FindObjectsOfType<GameObject>();
  346. // for (int i_i = 0; i_i < Allplayers.Length; i_i++) {
  347. // if (Allplayers [i_i].tag == "small") {
  348. small = false;
  349. gameObject.tag = "small";
  350. RpcSmall ();
  351. // }
  352. //}
  353. }
  354.  
  355. void MakeSmall(bool visibility){
  356. //Debug.Log (visibility);
  357. gameObject.GetComponent<MeshRenderer> ().enabled = false;
  358. MeshCharacterA.SetActive(true); //make people see large mesh as your character
  359. m_Animator = MeshCharacterA.GetComponent<NetworkAnimator>();
  360. The_animator = MeshCharacterA.GetComponent<Animator> ();
  361. m_Animator.SetParameterAutoSend (0, true);
  362. }
  363.  
  364. [ClientRpc]
  365. void RpcSmall(){
  366. gameObject.GetComponent<MeshRenderer> ().enabled = false;
  367. MeshCharacterA.SetActive(true);
  368. m_Animator = MeshCharacterA.GetComponent<NetworkAnimator>();
  369. The_animator = MeshCharacterA.GetComponent<Animator> ();
  370. m_Animator.SetParameterAutoSend (0, true);
  371. gameObject.tag = "small";
  372. }
  373.  
  374. [Command]
  375. void CmdRecordData(float playerX, float playerY, float playerZ, string toFindUsername){
  376. RECORDSTUFF (playerX, playerY, playerZ, toFindUsername);
  377. }
  378.  
  379. /*void OnServerConnect(){
  380. if (gameObject.tag == "small") {
  381. CmdMeshSmall ();
  382. CmdUpdateMeshSmall ();
  383. RpcSendSmall ();
  384. RpcSmall ();
  385. }
  386. }*/
  387.  
  388. void OnStartLocalPlayer(){
  389. GetComponent<NetworkAnimator> ().SetParameterAutoSend (0, true);
  390.  
  391. //For all players -> Have them update based on size
  392.  
  393. /*for gameObject in scene
  394. if gameObject name = small
  395. CmdMeshSmall ();
  396. CmdUpdateMeshSmall ();*/
  397.  
  398. CmdMeshSmall (); //This isn't working
  399. CmdUpdateMeshSmall ();
  400. RpcSendSmall ();
  401. RpcSmall ();
  402.  
  403. if (large == true) {
  404. RpcLarge ();
  405. }
  406. }
  407.  
  408. void OnPlayerEntered(int numberPlayers){
  409. CmdMeshSmall (); //Throwing these four lines in UPDATE works... But that does not seem right
  410. CmdUpdateMeshSmall ();
  411. RpcSendSmall ();
  412. RpcSmall ();
  413. }
  414.  
  415. public override void PreStartClient(){
  416. GetComponent<NetworkAnimator> ().SetParameterAutoSend (0, true);
  417. }
  418.  
  419. void RECORDSTUFF(float playerX, float playerY, float playerZ, string toFindUsername){
  420. string path = "Assets/Resources/test.txt";
  421.  
  422. /*static void lineChanger(string newText, string fileName . int line_to_edit) {
  423. */
  424.  
  425. StreamReader reader = new StreamReader(path);
  426. string text2 = " ";
  427.  
  428. int incrementing_counter = 0;
  429. bool nameFound = false;
  430. //MAKE THE FILE [USERNAME \n PASSWORD \n DATA \n USERNAME \n PASSWORD \n DATA \n etc... ]
  431. while (text2 != null) {
  432. incrementing_counter++;
  433. text2 = reader.ReadLine(); //Username
  434. //Debug.Log(toFindUsername);
  435. if (text2 == toFindUsername) {
  436. //Debug.Log ("(OJPI#NKLC");
  437. Line_of_the_username_in_the_file = incrementing_counter;
  438. Debug.Log (Line_of_the_username_in_the_file);
  439. nameFound = true;
  440. }
  441. }
  442. reader.Close();
  443.  
  444.  
  445. int line_to_edit = Line_of_the_username_in_the_file; //THERE IS NO '0' INDEX
  446.  
  447. if (nameFound == true) {
  448. string[] arrLine = File.ReadAllLines (path);
  449. for (int ik = 0; ik < arrLine.Length; ik++) {
  450. print (arrLine [ik]);
  451. }
  452. arrLine [line_to_edit + 1] = "" + (playerX+2) + "," + playerY + "," + playerZ;
  453. File.WriteAllLines (path, arrLine);
  454. }
  455.  
  456. /*}*/
  457. }
  458.  
  459. private float t = 0;
  460.  
  461. /*
  462. IEnumerator exitGame(){
  463. NetworkManager.singleton.client.Disconnect (); //THIS LEAVES BEHIND A GAMEOBJECT THAT SHOULDN'T BE THERE ?
  464. yield return new WaitForSeconds(1);
  465. Application.Quit (); //THIS WORKS BUT CAUSES A TIMEOUT
  466. yield return null;
  467. }
  468. */
  469. [Command]
  470. void CmdAnimateMove(){ //Client sends to server a request for animation to play
  471. m_Animator.animator.SetBool ("Weak_Attack", false);
  472. m_Animator.animator.SetBool ("WASD_pressed_to_move", true);
  473. RpcAnimateMove (); //that request gets passed and displayed to all clients
  474. }
  475.  
  476. [ClientRpc]
  477. void RpcAnimateMove(){
  478. m_Animator.animator.SetBool ("Weak_Attack", false);
  479. m_Animator.animator.SetBool("WASD_pressed_to_move", true);
  480. }
  481.  
  482. [Command]
  483. void CmdAnimateDontMove(){
  484. m_Animator.animator.SetBool ("Weak_Attack", false);
  485. m_Animator.animator.SetBool ("WASD_pressed_to_move", false);
  486. RpcAnimateDontMove ();
  487. }
  488.  
  489. [Command]
  490. void CmdAnimateWkAttack(){
  491. m_Animator.animator.SetBool ("Weak_Attack", true);
  492. //m_Animator.animator.SetBool ("Weak_Attack", false);
  493. RpcAnimateWkAttack ();
  494. }
  495.  
  496. [ClientRpc]
  497. void RpcAnimateWkAttack(){
  498. m_Animator.animator.SetBool ("Weak_Attack", true);
  499. //m_Animator.animator.SetBool ("Weak_Attack", false);
  500. }
  501.  
  502. [ClientRpc]
  503. void RpcAnimateDontMove(){
  504. m_Animator.animator.SetBool ("Weak_Attack", false);
  505. m_Animator.animator.SetBool ("WASD_pressed_to_move", false);
  506. }
  507.  
  508. [Command]
  509. void CmdStopMove(){
  510. m_Animator.animator.SetBool ("WASD_pressed_to_move", false);
  511. }
  512.  
  513. private void Update()
  514. {
  515. //m_Animator.SetParameterAutoSend (0, true);
  516. //print (!isLocalPlayer);
  517. if (isServer) {
  518. playerCamera.SetActive (false);
  519. waterCameras.SetActive (false);
  520. }
  521.  
  522.  
  523. //THE USERNAME AND PASSWORD CANNOT BE THE SAME AS AN ALREADY EXISTING ONE. "TQT" as username, also cannot have "TQT" as password
  524.  
  525. //Escape quits this game
  526. /*if (!isServer && Input.GetKey(KeyCode.Escape) && Input.GetKey(KeyCode.Q)) {
  527. //if(!isServer){
  528. //for(A FOR LOOP){
  529. // if (fileget() == DataToSendToGame.username) {
  530. // Line_of_the_username_in_the_file = <insert number here>;
  531. // }
  532. //}
  533.  
  534. //string path = "Assets/Resources/test.txt";
  535.  
  536. //static void lineChanger(string newText, string fileName . int line_to_edit) {
  537.  
  538. string path = "Assets/Resources/test.txt";
  539.  
  540. StreamReader reader = new StreamReader(path);
  541. string text2 = " ";
  542.  
  543. int incrementing_counter = 0;
  544. bool nameFound = false;
  545. //MAKE THE FILE [USERNAME \n PASSWORD \n DATA \n USERNAME \n PASSWORD \n DATA \n etc... ]
  546. while (text2 != null) {
  547. incrementing_counter++;
  548. text2 = reader.ReadLine(); //Username
  549. if (text2 == DataToSendToGame.username) {
  550. Line_of_the_username_in_the_file = incrementing_counter;
  551. nameFound = true;
  552. }
  553. }
  554. reader.Close();
  555.  
  556.  
  557. int line_to_edit = Line_of_the_username_in_the_file; //THERE IS NO '0' INDEX
  558.  
  559. if (nameFound == true) {
  560. string[] arrLine = File.ReadAllLines (path);
  561. arrLine [line_to_edit + 1] = "" + transform.position.x + "," + transform.position.y + "," + transform.position.z;
  562. File.WriteAllLines (path, arrLine);
  563. }
  564.  
  565.  
  566.  
  567. NetworkManager.singleton.StopClient();
  568. //Application.Quit (); //if the password is wrong, crash!
  569. //}
  570. }*/
  571.  
  572.  
  573. //int Line_of_the_username_in_the_file = 0;
  574. //Escape quits this game
  575. if (Save_and_quit == true) {
  576. //if(!isServer){
  577. /*for(A FOR LOOP){
  578. if (fileget() == DataToSendToGame.username) {
  579. Line_of_the_username_in_the_file = <insert number here>;
  580. }
  581. }*/
  582. //Debug.Log ("OPIWNKEFMPJIL");
  583. if (!isServer) {
  584. CmdRecordData (transform.position.x, transform.position.y, transform.position.z, DataToSendToGame.username);
  585. }
  586. /*string path = "Assets/Resources/test.txt";
  587. System.IO.StreamReader reader = new System.IO.StreamReader (path);
  588.  
  589. //static void lineChanger(string newText, string fileName . int line_to_edit) {
  590.  
  591.  
  592. //StreamReader reader = new StreamReader(path);
  593. string text2 = " ";
  594.  
  595. int incrementing_counter = 0;
  596. bool nameFound = false;
  597. //MAKE THE FILE [USERNAME \n PASSWORD \n DATA \n USERNAME \n PASSWORD \n DATA \n etc... ]
  598. while (text2 != null) {
  599. incrementing_counter++;
  600. text2 = reader.ReadLine(); //Username, this needs to loop back to the file start
  601. if (text2 == DataToSendToGame.username) {
  602. Line_of_the_username_in_the_file = incrementing_counter;
  603.  
  604. //AmmoText2.text = "q" + Line_of_the_username_in_the_file;
  605. nameFound = true;
  606. }
  607. }
  608. //end of reading
  609. //reader.DiscardBufferedData();
  610. reader.BaseStream.Position = 0; //Sets reader to start of file
  611. reader.Close();
  612.  
  613. int line_to_edit = Line_of_the_username_in_the_file; //THERE IS NO '0' INDEX
  614.  
  615. if (nameFound == true) {
  616. string[] arrLine = File.ReadAllLines (path);
  617. arrLine [line_to_edit + 1] = "" + (transform.position.x+5) + "," + transform.position.y + "," + transform.position.z;
  618. File.WriteAllLines (path, arrLine);
  619. }
  620. //}
  621. //line_to_edit = 0;
  622.  
  623. //NetworkManager.singleton.StopClient();*/
  624.  
  625. if(isLocalPlayer){
  626. //NetworkManager.Destroy (gameObject);\
  627.  
  628. //THIS (THE COMMENTED OUT STUFF) PREVENTS THE TIMEOUT BUT DOES NOT SAVE THE DATA
  629. //Destroy(gameObject);
  630. //transform.position = new Vector3 (0, 0, 0);
  631.  
  632. //NetworkManager.singleton.client.Disconnect (); //THIS LEAVES BEHIND A GAMEOBJECT THAT SHOULDN'T BE THERE ?
  633. //WaitForSeconds(1);
  634. Application.Quit (); //THIS WORKS BUT CAUSES A TIMEOUT -- ONLY FOR THE EDITOR -- FOR THE BUILD AND RUN AS SERVER IT IS FINE
  635.  
  636. //StartCoroutine (exitGame());
  637.  
  638. //NOT SURE IF THE BELOW LINE IS NECESSARY -- CAN'T TELL IF ON THE VM IF THE CLIENTS CAN CONNECT AFTER DISCONNECTING OR NOT
  639.  
  640.  
  641. //Application.Quit (); //if the password is wrong, crash!
  642. /*if (!isServer) {
  643. NetworkClient.ShutdownAll();
  644.  
  645. //then destroy me
  646. Destroy(gameObject);
  647. }*/
  648.  
  649. }
  650. //}
  651. //NetworkManager.singleton.StopClient();
  652. }
  653.  
  654. if (!isLocalPlayer) {
  655. camera.enabled = false;
  656. canvas.SetActive (false);
  657. listener.enabled = false;
  658. //bulletSpawn.SetActive (false);
  659. //bulletSpawn2.SetActive (false);
  660. return;
  661. }
  662.  
  663. //move everything left 1.
  664. if (Input.GetKeyDown (KeyCode.Mouse1)) { // THESE ARE LIKE FUNCTIONS
  665. string first = cards [0];
  666. for (int i = 0; i < 4; i++) {
  667. cards [i] = cards [i + 1];
  668. }
  669. cards [4] = first;
  670.  
  671. book.text = "{ [" + cards[0] + "],[" + cards[1] + "],[" + cards[2] + "],[" + cards[3] + "],[" + cards[4] + "] }";
  672. }
  673.  
  674.  
  675.  
  676. bool startfly = false;
  677. bool startparry = false;
  678. bool fireball = false;
  679.  
  680. //left most becomes 'last'. Shift everything down by 1, new number enters the right
  681. // length = 0, 0 = 1, 1 = 2 etc...
  682. if (Input.GetKeyDown (KeyCode.Mouse0)) {
  683. first = cards [0];
  684. for (int i = 0; i < cards.Length; i++) {
  685. if (i == cards.Length - 1) {
  686. cards [i] = first;
  687. } else {
  688. cards [i] = cards [i + 1]; //If you index to 1 more than length, and run this 'function' with pressing Q, it just exits the function and does not get to the print line.
  689. }
  690. }
  691.  
  692. book.text = "{ [" + cards[0] + "],[" + cards[1] + "],[" + cards[2] + "],[" + cards[3] + "],[" + cards[4] + "] }";
  693.  
  694. //arbitrarly, in this horizontal slice, all odd cards are 'parry' and all even cards are flight. In reality, usually 2 in the deck of each would be
  695. if(int.Parse(first) % 4 == 0){
  696. fireball = true;
  697. }else if (int.Parse(first) % 2 == 0) {
  698. startfly = true;
  699. } else {
  700. startparry = true;
  701. }
  702. waitTime3 = Time.time + float.Parse(first);
  703. }
  704.  
  705.  
  706. if (fireball || isSpellCasting) {
  707. isSpellCasting = true;
  708. string gun2 = "pistol"; //THIS MUST BE 'PISTOL' OR 'SHOTGUN' UNTIL NEW "SPELLS" ARE IMPLEMENTED
  709. string shooter2; //who is shooting
  710. // Debug.Log(playerSize2[1]);
  711. bool tempBool2 = true;
  712. bool breakingbool1 = true;
  713. //THIS IS BAD -- TRY SOME TYPE OF IF STATEMENT 'LOCKING' IN MAIN, where only 2 options are available in update because of a bool becoming true
  714. if (Input.GetKeyDown (KeyCode.Mouse0)) {
  715. //printPlayers ();
  716. for (int i = 0; i < Health.players.Length; i++) {
  717. if (Health.players [i] == ((gameObject.GetComponent<NetworkIdentity> ().netId).ToString ())) {
  718. if (true /*Health.small_ammo [i] > 0*/) {
  719. shooter2 = (gameObject.GetComponent<NetworkIdentity> ().netId).ToString ();
  720. CmdFire (bulletSpawn.transform.position - bulletSpawn2.transform.position, bulletSpawn.transform.position, bulletSpawn.transform.rotation, gun2, shooter2);
  721. fireball = false;
  722. isSpellCasting = false;
  723. }
  724. }
  725. }
  726.  
  727. } else if (Input.GetKeyDown (KeyCode.W) || Input.GetKeyDown (KeyCode.A) || Input.GetKeyDown (KeyCode.S) || Input.GetKeyDown (KeyCode.D)) {
  728. isSpellCasting = false;
  729. fireball = false;//Spell fizzle -- You do not get the card back, but something is refunded based on the 'fizzle effect' and deck cooldown is 'lower'
  730. }
  731. }
  732.  
  733.  
  734. if (gameObject.name == "large") {
  735. RpcLarge ();
  736. }
  737.  
  738. if (startfly) {
  739. fly = true;
  740. }
  741. if (startparry) {
  742. parry = true;
  743. }
  744.  
  745. if (fly) {
  746.  
  747. this._rigidbody3d.useGravity = false; //REMOVE THIS LINE and it becomes like a 'high jump' -- which can be used as a card
  748.  
  749. if (Input.GetKey (KeyCode.Space)) {
  750. transform.position = transform.position + (Camera.main.transform.up - (new Vector3(0f, Camera.main.transform.forward.y, 0f))) * _speed * Time.deltaTime;
  751. }
  752. if(Input.GetKey(KeyCode.LeftShift)){
  753. transform.position = transform.position - (Camera.main.transform.up - (new Vector3(0f, Camera.main.transform.forward.y, 0f))) * _speed * Time.deltaTime;
  754. }
  755. if (Time.time > waitTime3) {
  756. fly = false;
  757. //this._rigidbody3d.useGravity = true;
  758. }
  759. }
  760.  
  761. if (parry) {
  762. //whatever parry is -- technically testing this is an 'experience', requires something to shoot at you, then you parry it.
  763. if (Time.time > waitTime3) {
  764. parry = false;
  765. }
  766. }
  767.  
  768.  
  769. Cursor.lockState = CursorLockMode.Locked;
  770.  
  771.  
  772. position = new Rect ((Screen.width - crosshair.width) / 2, (Screen.height - crosshair.height) / 2, crosshair.width, crosshair.height);
  773.  
  774. //If the player is high up above the terrain, increase render distance
  775. if (gameObject.transform.position.y > 135f) {//current cutoff for high ground view is -20 [should see cities below and far into the ocean]
  776. camera.farClipPlane = 1500;
  777. } else {
  778. camera.farClipPlane = 800; //low ground [can't see far into the ocean]
  779. }
  780.  
  781. RaycastHit hit;
  782. Ray ray = camera.ScreenPointToRay (Input.mousePosition);
  783. int temp_index = FindInPlayers ((gameObject.GetComponent<NetworkIdentity> ().netId).ToString ());
  784.  
  785. //item0 is the compass
  786. if (Input.GetKeyDown (KeyCode.Alpha0)) {
  787. activeItem = Health.item0;
  788. items.text = "*0* 1 2 3 4 5 6 compass";
  789. }
  790. if (Input.GetKeyDown (KeyCode.Alpha1)) {
  791. activeItem = Health.item1;
  792. items.text = "0 *1* 2 3 4 5 6 " + Health.item1 [temp_index];
  793. }
  794. if (Input.GetKeyDown (KeyCode.Alpha2)) {
  795. activeItem = Health.item2;
  796. items.text = "0 1 *2* 3 4 5 6 " + Health.item2 [temp_index];
  797. }
  798. if (Input.GetKeyDown (KeyCode.Alpha3)) {
  799. activeItem = Health.item3;
  800. items.text = "0 1 2 *3* 4 5 6 " + Health.item3 [temp_index];
  801. }
  802. if (Input.GetKeyDown (KeyCode.Alpha4)) {
  803. activeItem = Health.item4;
  804. items.text = "0 1 2 3 *4* 5 6 " + Health.item4 [temp_index];
  805. }
  806. if (Input.GetKeyDown (KeyCode.Alpha5)) {
  807. activeItem = Health.item5;
  808. items.text = "0 1 2 3 4 *5* 6 " + Health.item5 [temp_index];
  809. }
  810. if (Input.GetKeyDown (KeyCode.Alpha6)) {
  811. activeItem = Health.item6;
  812. items.text = "0 1 2 3 4 5 *6* " + Health.item6 [temp_index];
  813. }
  814.  
  815. LayerMask mask = LayerMask.GetMask ("PickUPS");
  816.  
  817. //LIGHT MOVEMENT, SPAWN AT EACH PLAYER'S POSITION!!!! THIS WILL SPAWN IT AT THE PAD POSITIONS
  818. /*if (Time.time > waitTime2 + 0.5f && gameObject.activeInHierarchy) {
  819. var Clones = GameObject.FindGameObjectsWithTag ("Light2");//Destroy all solid light
  820. for (int i = 0; i < Clones.Length; i++) {
  821. Destroy (Clones [i]);
  822. }
  823. }
  824. //change the top if and if below by opposite operation to adjust lerping stats
  825. if (Time.time > waitTime2 + 0.5f && gameObject.activeInHierarchy && Time.time < waitTime2 + 2) {
  826. lerp = true;
  827. } else {
  828. lerp = false;
  829. }
  830.  
  831. if (lerp) {
  832. t += 0.01f;
  833. var Clones = GameObject.FindGameObjectsWithTag ("Light");
  834. for (int i = 0; i < Clones.Length; i++){
  835. Clones [i].GetComponent<Renderer> ().material.color = Color.Lerp (Color.white, Color.clear, t);//lerp the transparent light
  836. //every frame the lerp gets 1% closer to 1. 0 -> 1, at 1 done lerping
  837. }
  838. }
  839.  
  840. if(Time.time > waitTime2 + 1.25f && gameObject.activeInHierarchy){
  841. var Clones = GameObject.FindGameObjectsWithTag ("Light");
  842. for(int i = 0; i < Clones.Length; i++){
  843. Clones [i].transform.position += new Vector3 (0, 5, 0);
  844.  
  845. if (Clones [i].transform.localScale.x > 0) {
  846. Clones [i].transform.localScale += new Vector3 (-0.05f, 0, -0.05f);
  847. }
  848. }
  849. }
  850.  
  851. if(Time.time > waitTime2+5 && gameObject.activeInHierarchy){
  852. var Clones = GameObject.FindGameObjectsWithTag ("Light");
  853. for(int i = 0; i < Clones.Length; i++){
  854. Destroy (Clones [i]);
  855. }
  856. }*/
  857. //END OF LERPING
  858.  
  859. //can't move during first 2 seconds
  860. if (Time.time < waitTime2 + 1) {
  861. return;
  862. }
  863.  
  864. if (Physics.Raycast (ray, out hit, 10f, mask)) {
  865. Transform objectHit = hit.transform;
  866. // print (hit.transform.name);
  867. if (hit.transform.tag == "PickUp" && Input.GetKeyDown (KeyCode.F) && (Health.item1 [temp_index] != hit.transform.name && Health.item2 [temp_index] != hit.transform.name && Health.item3 [temp_index] != hit.transform.name && Health.item4 [temp_index] != hit.transform.name && Health.item5 [temp_index] != hit.transform.name && Health.item6 [temp_index] != hit.transform.name)) {
  868. if (Health.item1 [temp_index] == null) {
  869. Health.item1 [temp_index] = hit.transform.name;
  870. } else if (Health.item2 [temp_index] == null) {
  871. Health.item2 [temp_index] = hit.transform.name;
  872. } else if (Health.item3 [temp_index] == null) {
  873. Health.item3 [temp_index] = hit.transform.name;
  874. } else if (Health.item4 [temp_index] == null) {
  875. Health.item4 [temp_index] = hit.transform.name;
  876. } else if (Health.item5 [temp_index] == null) {
  877. Health.item5 [temp_index] = hit.transform.name;
  878. } else if (Health.item6 [temp_index] == null) {
  879. Health.item6 [temp_index] = hit.transform.name;
  880. } else {
  881. if (activeItem != Health.item0) {
  882. //drop the item, send it to server. Name the instantiated thing activeItem[temp_index] and give it PickUp tag.
  883. //CmdDrop (activeItem [temp_index]);
  884. for(int j = 0; j < 100; j++){
  885. if (Health.extra [temp_index, j] == null) {
  886. Health.extra [temp_index, j] = activeItem [temp_index];
  887. print (Health.extra [temp_index, j]);
  888. break;
  889. }
  890. }
  891. activeItem [temp_index] = hit.transform.name;
  892. }
  893. }
  894. if (isClient) {
  895. CmdDestroy (hit.transform.gameObject);
  896. }
  897. }
  898. }
  899.  
  900.  
  901. if (gameObject.GetComponent<Collider> ().enabled == false) {
  902. return;
  903. }
  904. /* HAVE AN ARRAY OF "PLAYER CLASS" OBJECT, EACH PLAYER HAS THEIR NETID AS A MEMBER [gain points when picking up gems, this is a kill register]
  905. * LOOP THROUGH THAT ARRAY, IF THE NET ID OF THIS GAMEOBJECT MATCHES THEN THAT IS THE PLAYER THAT IS SHOOTING
  906. * 100 "VICTORY" POINTS TO WIN, GAIN FROM KILLING OPPONENTS [+1 bonus per kill every 3 kills in a life] AND STAYING ALIVE FOR A CERTAIN AMOUNT OF TIME
  907. * -> EACH kill has a base worth of 3. Plus 1 for every 2 kills that player got and plus 1 for every 2 minutes that player was alive.
  908. * Gain points equal to 2 times the amount of minutes survived, i.e. after 1 minute gain 2 points, after 2 minutes gain 4 points etc. */
  909. //THE ABOVE WILL NOT BE IMPLEMENTED, IT PROBABLY WILL NEVER AND SHOULD NEVER BE...
  910.  
  911. string gun = activeItem[temp_index]; //what gun to use for the "fire" function. Default pistol
  912. string shooter; //who is shooting
  913. // Debug.Log(playerSize2[1]);
  914. bool tempBool = true;
  915. if (Input.GetKeyDown (KeyCode.Mouse0) && (gun == "pistol" || gun == "AR")) {
  916. //printPlayers ();
  917. for (int i = 0; i < Health.players.Length; i++) {
  918. if (Health.players [i] == ((gameObject.GetComponent<NetworkIdentity> ().netId).ToString ())) {
  919. if (true /*Health.small_ammo [i] > 0*/) {
  920. Health.small_ammo [i] -= 1;
  921. AmmoText.text = "S" + Health.small_ammo [i].ToString ();
  922. shooter = (gameObject.GetComponent<NetworkIdentity> ().netId).ToString ();
  923. CmdFire (bulletSpawn.transform.position - bulletSpawn2.transform.position, bulletSpawn.transform.position, bulletSpawn.transform.rotation, gun, shooter);
  924. break;
  925. }
  926. }
  927. }
  928. } else if (Input.GetKeyDown (KeyCode.Mouse0) && (gun == "Shotgun" || gun == "Rocket") && Time.time > waitTime && GetIndex() != 100 && playerSize2[GetIndex()] == "large") {
  929. //cooldown for shotgun is 1 seconds
  930. waitTime = Time.time + 1;
  931. for (int i = 0; i < Health.players.Length; i++) {
  932. if (Health.players [i] == ((gameObject.GetComponent<NetworkIdentity> ().netId).ToString ())) {
  933. if (true/*Health.small_ammo [i] > 0*/) {
  934. Health.small_ammo [i] -= 1;
  935. AmmoText.text = "S" + Health.small_ammo [i].ToString ();
  936. shooter = (gameObject.GetComponent<NetworkIdentity> ().netId).ToString ();
  937. CmdFire (bulletSpawn.transform.position - bulletSpawn2.transform.position, bulletSpawn.transform.position, bulletSpawn.transform.rotation, gun, shooter);
  938. break;
  939. }
  940. }
  941. }
  942. } else if (Input.GetKeyDown(KeyCode.Mouse0) && gun == "compass" && Time.time > waitTime){
  943. //cooldown for compass is 10 seconds
  944. waitTime = Time.time + 10;
  945. Drawline (transform.position, transform.rotation);
  946. }
  947.  
  948. if (playerSize2[GetIndex()] == "large" && gameObject.GetComponent<MeshRenderer> ().enabled == true && Time.time > waitTime2 /*&& islocalplayer*/ ) {//this becomes true after 10 seconds
  949. CmdMeshLarge();//This disables the default for the large character, now do another if that makes a different mesh get rendered as "true"
  950. }
  951.  
  952. if (playerSize2[GetIndex()] == "small" && gameObject.GetComponent<MeshRenderer> ().enabled == true && Time.time > waitTime2 /*&& isLocalplayer*/ ) {//this becomes true after 10 seconds
  953. CmdMeshSmall();//This disables the default for the large character, now do another if that makes a different mesh get rendered as "true"
  954. }
  955.  
  956. //print (GameObject.FindGameObjectsWithTag ("Player").Length > numPlayers);
  957. if(GameObject.FindGameObjectsWithTag ("Player").Length > numPlayers){
  958. //THIS WORKS, JUST NEED AN IF CHECK SO THAT IT STOPS WHEN A PLAYER DIES
  959. if (isLocalPlayer && lifeGemNOTcritboxGem.activeInHierarchy == false) {
  960. if (playerSize2[GetIndex()] == "large") {
  961. CmdUpdateMeshLarge (); //send mesh to everyone so they see it right
  962. }
  963. }
  964.  
  965. /*if (isLocalPlayer && lifeGemNOTcritboxGem.activeInHierarchy == true) {
  966. if (playerSize2[GetIndex()] == "large") {
  967. CmdRemoveMeshLarge (); //send mesh to everyone so they see it right
  968. }
  969. } */
  970.  
  971. //This print is attached to both players and does not work as each will print something different. Make it so these stop on player death.
  972. //Something like a "die" function that sends a variable into here when a player dies so that it stops updating the models.
  973.  
  974. if (isLocalPlayer && lifeGemNOTcritboxGem.activeInHierarchy == false) {
  975. if(playerSize2[GetIndex()] == "small"){
  976. CmdUpdateMeshSmall (); //send mesh to everyone so they see it right
  977. }
  978. }
  979.  
  980. /*if (isLocalPlayer && lifeGemNOTcritboxGem.activeInHierarchy == true) {
  981. if(playerSize2[GetIndex()] == "small"){
  982. CmdRemoveMeshSmall (); //send mesh to everyone so they see it right
  983. }
  984. }*/
  985. numPlayers = GameObject.FindGameObjectsWithTag ("Player").Length;
  986. }
  987.  
  988. //Camera Rotation THIS FOR SOME REASON DOESN'T SEEM TO BE NETWORKED
  989. y = Input.GetAxis("Mouse X");
  990. x = Input.GetAxis ("Mouse Y");
  991.  
  992. rotateValue = new Vector3(x * (-1.0f)*(sensitivity), y * (sensitivity), 0);
  993.  
  994. //print (transform.eulerAngles + "-" + rotateValue);
  995. if (rotationChecker.transform.eulerAngles.x < 340 && rotationChecker.transform.eulerAngles.x > 300) {
  996. rotationChecker.transform.eulerAngles = new Vector3(340, rotationChecker.transform.eulerAngles.y, rotationChecker.transform.eulerAngles.z);
  997. }
  998. if (rotationChecker.transform.eulerAngles.x > 45 && rotationChecker.transform.eulerAngles.x < 90) {
  999. rotationChecker.transform.eulerAngles = new Vector3(45, rotationChecker.transform.eulerAngles.y, rotationChecker.transform.eulerAngles.z);
  1000. }
  1001. rotationChecker.transform.eulerAngles = rotationChecker.transform.eulerAngles - rotateValue;
  1002. //End of camera rotating
  1003.  
  1004.  
  1005.  
  1006. //Diagonals -> It takes approxiamately 4 minutes to go from end to end horizontally of the map created.
  1007. //The time it takes implies that the map from the sand of the pennisula to the wall horizontally is about 2/3's of the Fortnite island.
  1008. if(Input.GetKeyDown (KeyCode.V)) {
  1009. for (int i = 0; i < Health.players.Length; i++) {
  1010. if (Health.players [i] == ((gameObject.GetComponent<NetworkIdentity> ().netId).ToString ())) {
  1011. if (Time.time >= waitTime4) {
  1012. //Health.small_ammo [i] -= 1;
  1013. //AmmoText.text = "S" + Health.small_ammo [i].ToString ();
  1014. shooter = (gameObject.GetComponent<NetworkIdentity> ().netId).ToString ();
  1015. waitTime4 = Time.time + 1.0f;
  1016. CmdAnimateWkAttack ();
  1017. CmdFire (Vector3.up, gameObject.transform.position, gameObject.transform.rotation, "Weak_Attack", shooter);
  1018. break;
  1019. }
  1020. }
  1021. }
  1022. } else if (Input.GetKey (KeyCode.W) && (Input.GetKey (KeyCode.A))) {
  1023. transform.position = transform.position + (Camera.main.transform.forward - (new Vector3 (0f, Camera.main.transform.forward.y, 0f))) * (_speed / Mathf.Sqrt (2)) * Time.deltaTime;
  1024. transform.position = transform.position - Camera.main.transform.right * (_speed / Mathf.Sqrt (2)) * Time.deltaTime;
  1025. } else if (Input.GetKey (KeyCode.W) && (Input.GetKey (KeyCode.D))) {
  1026. transform.position = transform.position + (Camera.main.transform.forward - (new Vector3 (0f, Camera.main.transform.forward.y, 0f))) * (_speed / Mathf.Sqrt (2)) * Time.deltaTime;
  1027. transform.position = transform.position + Camera.main.transform.right * (_speed / Mathf.Sqrt (2)) * Time.deltaTime;
  1028. } else if (Input.GetKey (KeyCode.S) && (Input.GetKey (KeyCode.A))) {
  1029. transform.position = transform.position - (Camera.main.transform.forward - (new Vector3 (0f, Camera.main.transform.forward.y, 0f))) * (_speed / Mathf.Sqrt (2)) * Time.deltaTime;
  1030. transform.position = transform.position - Camera.main.transform.right * (_speed / Mathf.Sqrt (2)) * Time.deltaTime;
  1031. } else if (Input.GetKey (KeyCode.S) && (Input.GetKey (KeyCode.D))) {
  1032. transform.position = transform.position - (Camera.main.transform.forward - (new Vector3 (0f, Camera.main.transform.forward.y, 0f))) * (_speed / Mathf.Sqrt (2)) * Time.deltaTime;
  1033. transform.position = transform.position + Camera.main.transform.right * (_speed / Mathf.Sqrt (2)) * Time.deltaTime;
  1034. }
  1035. //single key
  1036. else if (Input.GetKey (KeyCode.W)) {
  1037. transform.position = transform.position + (Camera.main.transform.forward - (new Vector3 (0f, Camera.main.transform.forward.y, 0f))) * _speed * Time.deltaTime;
  1038. if(!(Input.GetKey(KeyCode.V))){
  1039. CmdAnimateMove (); //m_Animator.animator.SetBool ("WASD_pressed_to_move", true);
  1040. }
  1041. //isWalk = true;
  1042. } else if (Input.GetKey (KeyCode.S)) {
  1043. transform.position = transform.position - (Camera.main.transform.forward - (new Vector3 (0f, Camera.main.transform.forward.y, 0f))) * _speed * Time.deltaTime;
  1044. if(!(Input.GetKey(KeyCode.V))){
  1045. CmdAnimateMove (); //m_Animator.animator.SetBool ("WASD_pressed_to_move", true);
  1046. }
  1047. } else if (Input.GetKey (KeyCode.A)) {
  1048. transform.position = transform.position - Camera.main.transform.right * _speed * Time.deltaTime;
  1049. if(!(Input.GetKey(KeyCode.V))){
  1050. CmdAnimateMove (); //m_Animator.animator.SetBool ("WASD_pressed_to_move", true);
  1051. }
  1052. } else if (Input.GetKey (KeyCode.D)) {
  1053. transform.position = transform.position + Camera.main.transform.right * _speed * Time.deltaTime;
  1054. if(!(Input.GetKey(KeyCode.V))){
  1055. CmdAnimateMove (); //m_Animator.animator.SetBool ("WASD_pressed_to_move", true);
  1056. }
  1057. } else { //no key is pressed
  1058. if (!(Input.GetKey (KeyCode.V))) {
  1059. CmdAnimateDontMove ();
  1060. }
  1061. //m_Animator.animator.SetBool ("WASD_pressed_to_move", false);
  1062. //m_Animator.Stop
  1063. //isWalk = false;
  1064. }
  1065.  
  1066.  
  1067. //if (isWalk == true && !(The_animator == null)) {
  1068. // The_animator.SetBool ("WASD_pressed_to_move", true);
  1069. //} else if (isWalk == false && !(The_animator == null)) {
  1070. // The_animator.SetBool ("WASD_pressed_to_move", false);
  1071. //}
  1072.  
  1073.  
  1074. // other moving
  1075. // _rigidbody3d.AddForce(
  1076. // NaturalMovement.MatchVelocityForce(
  1077. // new Vector3(
  1078. // (transform.right * Input.GetAxis("Horizontal")).x,
  1079. // 0.0f,
  1080. // (transform.forward * Input.GetAxis("Vertical")).z) * _maxVelocity,
  1081. // new Vector3(_rigidbody3d.velocity.x, 0.0f, _rigidbody3d.velocity.z),
  1082. // _acceleration,
  1083. // _maxAcceleration));
  1084.  
  1085. //if the jump is higher than the max velocity then it equals the max
  1086. if (_rigidbody3d.velocity.y > _maxVelocity) {
  1087. _rigidbody3d.velocity = new Vector3 (_rigidbody3d.velocity.x, _maxVelocity, _rigidbody3d.velocity.z);
  1088. }
  1089.  
  1090. //If the player is floating then give it a small velocity so that the if will detect and prevent it.
  1091. if (_rigidbody3d.velocity.y == 0) {
  1092. _rigidbody3d.velocity = new Vector3 (_rigidbody3d.velocity.x, 0.003f, _rigidbody3d.velocity.z);
  1093. }
  1094. //previous jump controller || (_rigidbody3d.velocity.y >= 0 && _rigidbody3d.velocity.y <= 0.01)
  1095. if (Input.GetKeyDown (KeyCode.Space)) {
  1096. Vector3 dwn = transform.TransformDirection (Vector3.down);
  1097.  
  1098. //raycasts are nice because they take care of the ramp problem, also use raycasts for realistic platforming!!!
  1099. if (Physics.Raycast (transform.position, dwn, 1.5f)){
  1100. //_rigidbody3d.velocity = new Vector3 (_rigidbody3d.velocity.x, _jumpVelocity, _rigidbody3d.velocity.z)
  1101.  
  1102. //instead of the weird velocity thing just add an impulse
  1103. //_rigidbody3d.AddForce (new Vector3 (0, _jumpVelocity, 0), ForceMode.Impulse);
  1104. //THESE ARE 0 AND NEED TO BE FIXED, REMEMBER THE JUMPVELOCITY SHOULD INCREASE AS XY-PLANE MOVEMENT INCREASES
  1105. //print(_rigidbody3d.velocity.x);
  1106. //print (_rigidbody3d.velocity.z); //CHANGE THIS VALUE (the 4f) FOR JUMP HEIGHT
  1107. _rigidbody3d.velocity = (new Vector3 (_rigidbody3d.velocity.x, _jumpVelocity*4f, _rigidbody3d.velocity.z));
  1108.  
  1109. } //else {
  1110. //print ("There is nothing below the object!");
  1111. //}
  1112. }
  1113. /*if (_rigidbody3d.velocity.y > -0.02 && _rigidbody3d.velocity.y <= 0.001) {
  1114. _rigidbody3d.velocity = new Vector3 (_rigidbody3d.velocity.x, 0, _rigidbody3d.velocity.z);
  1115. _rigidbody3d.useGravity = false;
  1116. } else {
  1117. _rigidbody3d.useGravity = true;
  1118. //_rigidbody3d.velocity = new Vector3 (_rigidbody3d.velocity.x, 1, _rigidbody3d.velocity.z);
  1119. }*/
  1120.  
  1121. // Falling
  1122. if (_rigidbody3d.velocity.y < 0){ //CHANGE THIS VALUE FOR GRAVITY
  1123. _rigidbody3d.velocity += Vector3.up * Physics.gravity.y * 1.5f*4f * Time.deltaTime;
  1124. }
  1125.  
  1126. }
  1127.  
  1128. private void FixedUpdate()
  1129. {
  1130. _rigidbody3d.velocity = new Vector3(
  1131. NaturalMovement.CapVelocity(new Vector3(_rigidbody3d.velocity.x, 0.0f, _rigidbody3d.velocity.z), _maxVelocity).x,
  1132. _rigidbody3d.velocity.y, NaturalMovement.CapVelocity(new Vector3(_rigidbody3d.velocity.x, 0.0f, _rigidbody3d.velocity.z), _maxVelocity).z);
  1133. }
  1134.  
  1135. //returns the index of all data for that player, ideally all data for that player is that INDEX in all the other arrays. Copy-pasted into all scripts
  1136. public int FindInPlayers(string playerID){
  1137. for (int i = 0; i < Health.players.Length; i++) {
  1138. if (Health.players [i] == playerID) {
  1139. return i;
  1140. }
  1141. }
  1142. return 0;
  1143. }
  1144.  
  1145. //also placed into all scripts
  1146. void printPlayers(){
  1147. for (int i = 0; i < Health.players.Length; i++) {
  1148. Debug.Log (Health.players [i]);
  1149. }
  1150. }
  1151.  
  1152. [Command]
  1153. void CmdFire(Vector3 Direction, Vector3 bulletPosition, Quaternion bulletRotation, string gun, string shooter)
  1154. {
  1155. //use the shooter passed into here to record who shot the bullet and who was hit other.GetComponent<NetworkIdentity>().netID is the other person
  1156. if (gun == "pistol") {
  1157. // Create the Bullet from the Bullet Prefab
  1158. var bullet = (GameObject)Instantiate (
  1159. bulletPrefab,
  1160. bulletPosition,
  1161. bulletRotation);
  1162.  
  1163. //Ignore these two lines, they assign the shooter to the bullet for KDA purposes... which are not important for the demo.
  1164. bullet.name = shooter;//ONLY ON THE SERVER!!
  1165. GiveBulletName (bullet, shooter);
  1166.  
  1167. //print ("bullet" + transform.name);
  1168. //bullet.transform.parent = gameObject.transform;
  1169. bullet.GetComponent<Rigidbody> ().velocity = Direction.normalized * 60;
  1170. //print (rotationChecker.transform.rotation.eulerAngles); //position and rotation for each player can be tracked easily as data.
  1171.  
  1172. NetworkServer.Spawn (bullet);
  1173.  
  1174. // Destroy the bullet after 2 seconds
  1175. StartCoroutine (despawnBullet (bullet));
  1176. } else if (gun == "Shotgun") {
  1177. // Create the Bullet from the Bullet Prefab
  1178. var bullet = (GameObject)Instantiate (
  1179. ShotgunBulletPrefab,
  1180. bulletPosition,
  1181. bulletRotation);
  1182.  
  1183. //Ignore these two lines, they assign the shooter to the bullet for KDA purposes... which are not important for the demo.
  1184. bullet.name = shooter;
  1185. GiveBulletName (bullet, shooter);
  1186.  
  1187. //print ("bullet" + transform.name);
  1188. //bullet.transform.parent = gameObject.transform;
  1189. bullet.GetComponent<Rigidbody> ().velocity = Direction.normalized * 60;
  1190. //print (rotationChecker.transform.rotation.eulerAngles); //position and rotation for each player can be tracked easily as data.
  1191.  
  1192. NetworkServer.Spawn (bullet);
  1193.  
  1194. // Destroy the bullet after 2 seconds
  1195. StartCoroutine (despawnBullet (bullet));
  1196. } else if (gun == "Weak_Attack") {
  1197. var bullet = (GameObject)Instantiate (
  1198. WeakBulletPrefab,
  1199. bulletPosition,
  1200. bulletRotation);
  1201.  
  1202. //Ignore these two lines, they assign the shooter to the bullet for KDA purposes... which are not important for the demo.
  1203. bullet.name = shooter;
  1204. GiveBulletName (bullet, shooter);
  1205.  
  1206. //print ("bullet" + transform.name);
  1207. //bullet.transform.parent = gameObject.transform;
  1208. bullet.GetComponent<Rigidbody> ().velocity = Direction.normalized * 0;
  1209. //print (rotationChecker.transform.rotation.eulerAngles); //position and rotation for each player can be tracked easily as data.
  1210.  
  1211. NetworkServer.Spawn (bullet);
  1212.  
  1213. // Destroy the bullet after 2 seconds
  1214. StartCoroutine (despawnWeakAttack (bullet));
  1215. }
  1216. }
  1217.  
  1218. [Command]
  1219. void CmdDestroy(GameObject obj){
  1220. Destroy (obj);
  1221. }
  1222.  
  1223. void GiveBulletName(GameObject bullet, string shooter){
  1224. bullet.name = shooter;
  1225. }
  1226.  
  1227. void Drawline (Vector3 bulletPosition, Quaternion bulletRotation){
  1228. float disClosest = Mathf.Infinity;
  1229. Health enemyClosest = null;
  1230. Health[] allEnemies = GameObject.FindObjectsOfType<Health> ();
  1231.  
  1232. foreach (Health currentEnemy in allEnemies) {
  1233. float distanceTo = (currentEnemy.transform.position - this.transform.position).sqrMagnitude;
  1234. if (distanceTo < disClosest && distanceTo > 1.5f) {
  1235. disClosest = distanceTo;
  1236. enemyClosest = currentEnemy;
  1237. }
  1238. }
  1239.  
  1240. if (enemyClosest != null) {
  1241. //if there is an enemy that can be tracked then...
  1242. StartCoroutine(spawnTrackingBullets (bulletPosition, bulletRotation, enemyClosest));
  1243. }
  1244. }
  1245.  
  1246. IEnumerator spawnTrackingBullets(Vector3 bulletPosition, Quaternion bulletRotation, Health enemyClosest){
  1247. int counter = 0;
  1248. while (counter < 30) {
  1249. var bullet = (GameObject)Instantiate (
  1250. CompassBulletPrefab,
  1251. bulletPosition,
  1252. bulletRotation);
  1253.  
  1254. Vector3 directionTo = enemyClosest.transform.position - transform.position;
  1255. bullet.GetComponent<Rigidbody> ().velocity = directionTo.normalized * 20;
  1256.  
  1257. //Instantiate (bullet);
  1258.  
  1259. StartCoroutine (despawnNonServerBullet (bullet));
  1260.  
  1261. //because counter += 3 was not working...
  1262. counter++;
  1263. counter++;
  1264. counter++;
  1265.  
  1266. yield return new WaitForSeconds (0.25f);
  1267. }
  1268. }
  1269.  
  1270. IEnumerator despawnBullet(GameObject bullet){
  1271. yield return new WaitForSeconds (2.0f);
  1272. NetworkServer.Destroy (bullet);
  1273. }
  1274.  
  1275. IEnumerator despawnWeakAttack(GameObject bullet){
  1276. yield return new WaitForSeconds (0.7f);
  1277. NetworkServer.Destroy (bullet);
  1278. }
  1279.  
  1280. int GetIndex(){
  1281. for (int i = 0; i < Health.players.Length; i++) {
  1282. if (Health.players [i] == (gameObject.GetComponent<NetworkIdentity> ().netId).ToString ()) {
  1283. return i;
  1284. }
  1285. }
  1286. return 100;
  1287. }
  1288.  
  1289. IEnumerator despawnNonServerBullet(GameObject bullet){
  1290. yield return new WaitForSeconds (2.5f);
  1291. Destroy (bullet);
  1292. }
  1293. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement