Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using Mirror;
  6.  
  7. public class PlayerMover : NetworkBehaviour
  8. {
  9.  
  10. [SerializeField]
  11. private float speed;
  12. public string playerID;
  13. private string idlestate = "idle";
  14. public GameObject bulletspawn;
  15. public GameObject bullet;
  16. public GameObject wall;
  17. public GameObject wallspawn;
  18.  
  19.  
  20. [Command]
  21. void CmdWallSpawner()
  22. {
  23. GameObject wallspawner = Instantiate(wall, wallspawn.transform.position, transform.rotation);
  24. NetworkServer.Spawn(wallspawner);
  25. }
  26. [Command]
  27. void Cmdbulletspawner()
  28. {
  29. GameObject go = Instantiate(bullet, bulletspawn.transform.position, transform.rotation);
  30. NetworkServer.Spawn(go);
  31. Destroy(go, 5);
  32. }
  33.  
  34. private void OnDrawGizmosSelected()
  35. {
  36. Gizmos.color = Color.yellow;
  37. Gizmos.DrawSphere(wallspawn.transform.position, 1);
  38. }
  39.  
  40. void FixedUpdate()
  41. {
  42. if (this.isLocalPlayer)
  43. {
  44. float movement = Input.GetAxis("Horizontal");
  45. float movement2 = Input.GetAxis("Vertical");
  46. if (Input.GetKeyDown(KeyCode.Space))
  47. {
  48. if (idlestate == "sniper")
  49. {
  50. idlestate = "idle";
  51. GetComponent<Animator>().Play("idle");
  52. }
  53. else if (idlestate == "idle")
  54. {
  55. GetComponent<Animator>().Play("idlesniper");
  56. idlestate = "sniper";
  57. }
  58. else if (idlestate == "block")
  59. {
  60. idlestate = "idle";
  61. }
  62. }
  63. if (Input.GetAxisRaw("Vertical") != 0 && Input.GetAxisRaw("Horizontal") == 0)
  64. {
  65. GetComponent<Rigidbody2D>().velocity = new Vector2(0, movement2 * speed);
  66. }
  67. if (Input.GetAxisRaw("Horizontal") != 0 && Input.GetAxisRaw("Vertical") == 0)
  68. {
  69. GetComponent<Rigidbody2D>().velocity = new Vector2(movement * speed, 0);
  70. }
  71. else if (Input.GetAxisRaw("Horizontal") == 0 && Input.GetAxisRaw("Vertical") == 0)
  72. {
  73. GetComponent<Rigidbody2D>().velocity = new Vector2(0.0f, 0.0f);
  74. }
  75. if (Input.GetAxisRaw("Horizontal") != 0 && Input.GetAxisRaw("Vertical") != 0)
  76. {
  77. GetComponent<Rigidbody2D>().velocity = new Vector2(movement * speed, movement2 * speed);
  78.  
  79. }
  80. if (Input.GetMouseButtonDown(0))
  81. {
  82. if (idlestate == "idle")
  83. {
  84. GetComponent<Animator>().Play("New Animation");
  85. }
  86. else if (idlestate == "block")
  87. {
  88. Collider2D[] colliders = Physics2D.OverlapCircleAll(wallspawn.transform.position, 1f, 0);
  89. if (colliders.Length > 0)
  90. {
  91. CmdWallSpawner();
  92. }
  93. else
  94. {
  95. Debug.Log(colliders);
  96. }
  97. }
  98. else
  99. {
  100. GetComponent<Animator>().Play("snipershoot");
  101. Cmdbulletspawner();
  102. }
  103. }
  104. Vector3 diff = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
  105. diff.Normalize();
  106.  
  107. float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;
  108. transform.rotation = Quaternion.Euler(0f, 0f, rot_z - 90);
  109.  
  110. Camera.main.transform.position = new Vector3(transform.position.x, transform.position.y, Camera.main.transform.position.z);
  111.  
  112. // Object Placing Scripts
  113. if (Input.GetKeyDown(KeyCode.Q))
  114. {
  115. idlestate = "block";
  116. GetComponent<Animator>().Play("wall idle");
  117. }
  118.  
  119. }
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement