Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using Mirror;
- public class PlayerMover : NetworkBehaviour
- {
- [SerializeField]
- private float speed;
- public string playerID;
- private string idlestate = "idle";
- public GameObject bulletspawn;
- public GameObject bullet;
- public GameObject wall;
- public GameObject wallspawn;
- [Command]
- void CmdWallSpawner()
- {
- GameObject wallspawner = Instantiate(wall, wallspawn.transform.position, transform.rotation);
- NetworkServer.Spawn(wallspawner);
- }
- [Command]
- void Cmdbulletspawner()
- {
- GameObject go = Instantiate(bullet, bulletspawn.transform.position, transform.rotation);
- NetworkServer.Spawn(go);
- Destroy(go, 5);
- }
- private void OnDrawGizmosSelected()
- {
- Gizmos.color = Color.yellow;
- Gizmos.DrawSphere(wallspawn.transform.position, 1);
- }
- void FixedUpdate()
- {
- if (this.isLocalPlayer)
- {
- float movement = Input.GetAxis("Horizontal");
- float movement2 = Input.GetAxis("Vertical");
- if (Input.GetKeyDown(KeyCode.Space))
- {
- if (idlestate == "sniper")
- {
- idlestate = "idle";
- GetComponent<Animator>().Play("idle");
- }
- else if (idlestate == "idle")
- {
- GetComponent<Animator>().Play("idlesniper");
- idlestate = "sniper";
- }
- else if (idlestate == "block")
- {
- idlestate = "idle";
- }
- }
- if (Input.GetAxisRaw("Vertical") != 0 && Input.GetAxisRaw("Horizontal") == 0)
- {
- GetComponent<Rigidbody2D>().velocity = new Vector2(0, movement2 * speed);
- }
- if (Input.GetAxisRaw("Horizontal") != 0 && Input.GetAxisRaw("Vertical") == 0)
- {
- GetComponent<Rigidbody2D>().velocity = new Vector2(movement * speed, 0);
- }
- else if (Input.GetAxisRaw("Horizontal") == 0 && Input.GetAxisRaw("Vertical") == 0)
- {
- GetComponent<Rigidbody2D>().velocity = new Vector2(0.0f, 0.0f);
- }
- if (Input.GetAxisRaw("Horizontal") != 0 && Input.GetAxisRaw("Vertical") != 0)
- {
- GetComponent<Rigidbody2D>().velocity = new Vector2(movement * speed, movement2 * speed);
- }
- if (Input.GetMouseButtonDown(0))
- {
- if (idlestate == "idle")
- {
- GetComponent<Animator>().Play("New Animation");
- }
- else if (idlestate == "block")
- {
- Collider2D[] colliders = Physics2D.OverlapCircleAll(wallspawn.transform.position, 1f, 0);
- if (colliders.Length > 0)
- {
- CmdWallSpawner();
- }
- else
- {
- Debug.Log(colliders);
- }
- }
- else
- {
- GetComponent<Animator>().Play("snipershoot");
- Cmdbulletspawner();
- }
- }
- Vector3 diff = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
- diff.Normalize();
- float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;
- transform.rotation = Quaternion.Euler(0f, 0f, rot_z - 90);
- Camera.main.transform.position = new Vector3(transform.position.x, transform.position.y, Camera.main.transform.position.z);
- // Object Placing Scripts
- if (Input.GetKeyDown(KeyCode.Q))
- {
- idlestate = "block";
- GetComponent<Animator>().Play("wall idle");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement