Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Networking;
- public class NaturalMovementPlatforming : NetworkBehaviour
- {
- [SerializeField]
- private GameObject bulletPrefab;
- [SerializeField]
- private GameObject ShotgunBulletPrefab;
- [SerializeField]
- private GameObject CompassBulletPrefab;
- [SerializeField]
- private GameObject WeakBulletPrefab;
- [SerializeField]
- private GameObject bulletSpawn;
- [SerializeField]
- private GameObject bulletSpawn2;
- [SerializeField]
- private Camera camera;
- [SerializeField]
- private GameObject rotationChecker;
- private bool fly = false;
- private bool parry = false;
- [SerializeField]
- private GameObject waterCameras;
- [SerializeField]
- private GameObject playerCamera;
- [Header("Movement")]
- [SerializeField]
- private float _acceleration;
- [SerializeField]
- private float _maxAcceleration;
- [SerializeField]
- private float _maxVelocity;
- [Header("MoveSpeed")]
- [SerializeField]
- private float _speed;
- bool isGround = false;
- [Header("Jumping")]
- [SerializeField]
- private float _groundedDistance;
- [SerializeField]
- private float _jumpVelocity;
- [SerializeField]
- private float _jumpCooldown;
- //[SerializeField]
- //private bool Touching = false;
- [SerializeField]
- private float _hangtime;
- private Rigidbody _rigidbody3d;
- private float _jumpTimer;
- private Vector3 goForward = new Vector3(0,0,1);
- private Vector3 rotateValue;
- private float y;
- private float x;
- [Header("Sensitivity")]
- [SerializeField]
- private float sensitivity;
- [SerializeField]
- private GameObject canvas;
- [SerializeField]
- private Text AmmoText;
- [SerializeField]
- private Text AmmoText2;
- [SerializeField]
- private Text AmmoText3;
- [SerializeField]
- private Texture2D crosshair;
- [SerializeField]
- private Text items;
- [SerializeField]
- private Text book;
- [SerializeField]
- private AudioListener listener;
- private int Line_of_the_username_in_the_file = 0;
- [Header("Models")]
- [SerializeField]
- private GameObject MeshCharacterA;
- [SerializeField]
- private GameObject demoMesh;
- [SerializeField]
- private GameObject lifeGemNOTcritboxGem;
- private bool Save_and_quit = false;
- private int numPlayers = 0;
- private Rect position;
- private float waitTime;
- private float waitTime2;
- private float waitTime3;
- private float waitTime4;
- public static string[] playerSize2 = new string[20];
- private bool pointless = true;
- private static string[] cards = new string[20];
- private static string[] newCards = new string[20];
- private static GameObject[] Allplayers = new GameObject[10000]; //just a random number here...Max 10000 players?
- private string first;
- private bool isSpellCasting = false;
- //[SyncVar(hook = "MakeLarge")]
- [SyncVar]
- private bool large = true;
- //[SyncVar(hook = "MakeSmall")]
- [SyncVar]
- private bool small = true;
- //private LinkedList<string> cards = new LinkedList<string>();
- NetworkAnimator m_Animator;
- private Animator The_animator;
- [SyncVar]
- private bool isWalk = false;
- [SyncVar(hook = "OnPlayerEntered")]
- private int someoneEntered = 0;
- [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
- //private bool
- 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
- //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.
- //IT IS CURRENTLY CHECKING USERNAME AND PASSWORD -- THEREFORE IT IS A WORKING "MMO"
- //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
- private void Awake()
- {
- _rigidbody3d = GetComponent<Rigidbody>();
- Cursor.lockState = CursorLockMode.Locked;
- sensitivity = -1.5f;
- waitTime2 = Time.time + 1;
- for(int i = 0; i < cards.Length; i++){
- cards [i] = i.ToString();
- }
- book.text = "{ [" + cards[0] + "],[" + cards[1] + "],[" + cards[2] + "],[" + cards[3] + "],[" + cards[4] + "] }";
- }
- [Command]
- void CmdDebug(string toPrintThis){
- print(toPrintThis);
- }
- /*//check to see if the player is in contact with the ground, works on slopes too!
- //as long as the player collides with the ground then isGround is true
- void OnCollisionStay(Collision hit)
- {
- if (hit.gameObject.tag == "ground") {
- isGround = true;
- }
- }
- //when stop colliding with ground give 0.2 sec hang time
- void OnCollisionExit(Collision hit)
- {
- if (hit.gameObject.tag == "ground")
- {
- StartCoroutine(notcollidingwithGround());
- }
- }
- //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)
- IEnumerator notcollidingwithGround(){
- yield return new WaitForSeconds (_hangtime);
- isGround = false;
- }*/
- int index = 0;
- bool lerp = false;
- void OnTriggerEnter(Collider other){
- if (other.tag == "save_and_quit") {
- Save_and_quit = true;
- } else {
- Save_and_quit = false;
- }
- //---------------------------------------------------------
- //MAIN MENU
- if (other.name == "Play_Collider") {
- gameObject.transform.position = new Vector3 (0, 10, 110);
- }
- //---------------------------------------------------------
- //---------------------------------------------------------
- //CHARACTER SELECTION
- if (other.name == "Red_Character") {
- small = false;
- MakeSmall (true); //the true actually does nothing...
- CmdMeshSmall ();
- CmdUpdateMeshSmall ();
- gameObject.transform.position = new Vector3 (0, 10, 204);
- }
- if (other.name == "Blue_Character") {
- large = false;
- gameObject.transform.position = new Vector3 (0, 10, 204);
- }
- //---------------------------------------------------------
- //---------------------------------------------------------
- //ARENA SELECTION
- if (other.name == "Circle_Arena") {
- gameObject.transform.position = new Vector3 (1987, 70, 1114);
- }
- //---------------------------------------------------------
- if (other.name == "Entered_Battlefield") { //Need to do this for ALL players in battlefield
- someoneEntered += 1;
- OnPlayerEntered (1);
- }
- if (other.tag == "fall_off") {
- //communicate through UI that someone fell
- gameObject.transform.position = new Vector3(1987, 70, 1114); //respawns them
- }
- for (int i = 0; i < Health.players.Length; i++) {
- if (Health.players [i] == (gameObject.GetComponent<NetworkIdentity> ().netId).ToString()) {
- index = i;
- }
- }
- if (other.tag == "s_ammo") {
- Health.small_ammo[index] += 30;
- AmmoText.text = "S" + Health.small_ammo[index].ToString();
- } else if (other.tag == "m_ammo") {
- Health.medium_ammo[index] += 10;
- AmmoText2.text = "M" + Health.medium_ammo[index].ToString();
- } else if (other.tag == "l_ammo") {
- Health.large_ammo[index] += 3;
- AmmoText3.text = "L" + Health.large_ammo[index].ToString();
- }
- }
- void OnGUI() {
- GUI.DrawTexture (position, crosshair);
- }
- private string[] activeItem = Health.item0;
- [Command]
- void CmdMeshLarge(){
- large = false;
- //gameObject.tag = "large";
- RpcLarge ();
- }
- [Command]
- void CmdUpdateMeshLarge(){
- gameObject.GetComponent<MeshRenderer> ().enabled = false;
- demoMesh.SetActive(true); //make people see large mesh as your character
- //gameObject.tag = "large";
- RpcSendLarge();
- }
- [Command]
- void CmdRemoveMeshLarge(){
- demoMesh.SetActive(false); //make people see large mesh as your character
- RpcSendRemovedLarge();
- }
- [ClientRpc]
- void RpcSendLarge(){
- gameObject.GetComponent<MeshRenderer> ().enabled = false;
- demoMesh.SetActive(true); //make people see large mesh as your character
- //gameObject.tag = "large";
- }
- [ClientRpc]
- void RpcSendRemovedLarge(){
- demoMesh.SetActive(false); //make people see large mesh as your character
- }
- [ClientRpc]
- void RpcSendSmall(){
- gameObject.GetComponent<MeshRenderer> ().enabled = false;
- MeshCharacterA.SetActive(true); //make people see large mesh as your character
- m_Animator = MeshCharacterA.GetComponent<NetworkAnimator>();
- The_animator = MeshCharacterA.GetComponent<Animator> ();
- m_Animator.SetParameterAutoSend (0, true);
- gameObject.tag = "small";
- }
- [ClientRpc]
- void RpcSendRemovedSmall(){
- gameObject.GetComponent<MeshRenderer> ().enabled = false;
- MeshCharacterA.SetActive(true); //make people see large mesh as your character
- m_Animator = MeshCharacterA.GetComponent<NetworkAnimator>();
- The_animator = MeshCharacterA.GetComponent<Animator> ();
- m_Animator.SetParameterAutoSend (0, true);
- }
- [Command]
- void CmdUpdateMeshSmall(){
- //Allplayers = UnityEngine.Object.FindObjectsOfType<GameObject>();
- //for (int i_i = 0; i_i < Allplayers.Length; i_i++) {
- // if(Allplayers[i_i].tag == "small"){
- gameObject.GetComponent<MeshRenderer> ().enabled = false;
- MeshCharacterA.SetActive(true); //make people see large mesh as your character
- m_Animator = MeshCharacterA.GetComponent<NetworkAnimator>();
- The_animator = MeshCharacterA.GetComponent<Animator> ();
- m_Animator.SetParameterAutoSend (0, true);
- gameObject.tag = "small";
- RpcSendSmall();
- // }
- //}
- }
- /* [Command]
- void CmdRemoveMeshSmall(){
- gameObject.GetComponent<MeshRenderer> ().enabled = false;
- MeshCharacterA.SetActive(true); //make people see characterA mesh as your character
- RpcSendRemovedSmall();
- }*/
- void MakeLarge(bool visibility){
- //Debug.Log (visibility);
- gameObject.GetComponent<MeshRenderer> ().enabled = false;
- demoMesh.SetActive(true); //make people see large mesh as your character
- camera.transform.position = camera.transform.position + new Vector3(0,1,-1);
- }
- [ClientRpc]
- void RpcLarge(){
- gameObject.GetComponent<MeshRenderer> ().enabled = false;
- demoMesh.SetActive(true); //make people see large mesh as your character
- //gameObject.tag = "large";
- }
- [Command]
- void CmdMeshSmall(){
- //Allplayers = UnityEngine.Object.FindObjectsOfType<GameObject>();
- // for (int i_i = 0; i_i < Allplayers.Length; i_i++) {
- // if (Allplayers [i_i].tag == "small") {
- small = false;
- gameObject.tag = "small";
- RpcSmall ();
- // }
- //}
- }
- void MakeSmall(bool visibility){
- //Debug.Log (visibility);
- gameObject.GetComponent<MeshRenderer> ().enabled = false;
- MeshCharacterA.SetActive(true); //make people see large mesh as your character
- m_Animator = MeshCharacterA.GetComponent<NetworkAnimator>();
- The_animator = MeshCharacterA.GetComponent<Animator> ();
- m_Animator.SetParameterAutoSend (0, true);
- }
- [ClientRpc]
- void RpcSmall(){
- gameObject.GetComponent<MeshRenderer> ().enabled = false;
- MeshCharacterA.SetActive(true);
- m_Animator = MeshCharacterA.GetComponent<NetworkAnimator>();
- The_animator = MeshCharacterA.GetComponent<Animator> ();
- m_Animator.SetParameterAutoSend (0, true);
- gameObject.tag = "small";
- }
- [Command]
- void CmdRecordData(float playerX, float playerY, float playerZ, string toFindUsername){
- RECORDSTUFF (playerX, playerY, playerZ, toFindUsername);
- }
- /*void OnServerConnect(){
- if (gameObject.tag == "small") {
- CmdMeshSmall ();
- CmdUpdateMeshSmall ();
- RpcSendSmall ();
- RpcSmall ();
- }
- }*/
- void OnStartLocalPlayer(){
- GetComponent<NetworkAnimator> ().SetParameterAutoSend (0, true);
- //For all players -> Have them update based on size
- /*for gameObject in scene
- if gameObject name = small
- CmdMeshSmall ();
- CmdUpdateMeshSmall ();*/
- CmdMeshSmall (); //This isn't working
- CmdUpdateMeshSmall ();
- RpcSendSmall ();
- RpcSmall ();
- if (large == true) {
- RpcLarge ();
- }
- }
- void OnPlayerEntered(int numberPlayers){
- CmdMeshSmall (); //Throwing these four lines in UPDATE works... But that does not seem right
- CmdUpdateMeshSmall ();
- RpcSendSmall ();
- RpcSmall ();
- }
- public override void PreStartClient(){
- GetComponent<NetworkAnimator> ().SetParameterAutoSend (0, true);
- }
- void RECORDSTUFF(float playerX, float playerY, float playerZ, string toFindUsername){
- string path = "Assets/Resources/test.txt";
- /*static void lineChanger(string newText, string fileName . int line_to_edit) {
- */
- StreamReader reader = new StreamReader(path);
- string text2 = " ";
- int incrementing_counter = 0;
- bool nameFound = false;
- //MAKE THE FILE [USERNAME \n PASSWORD \n DATA \n USERNAME \n PASSWORD \n DATA \n etc... ]
- while (text2 != null) {
- incrementing_counter++;
- text2 = reader.ReadLine(); //Username
- //Debug.Log(toFindUsername);
- if (text2 == toFindUsername) {
- //Debug.Log ("(OJPI#NKLC");
- Line_of_the_username_in_the_file = incrementing_counter;
- Debug.Log (Line_of_the_username_in_the_file);
- nameFound = true;
- }
- }
- reader.Close();
- int line_to_edit = Line_of_the_username_in_the_file; //THERE IS NO '0' INDEX
- if (nameFound == true) {
- string[] arrLine = File.ReadAllLines (path);
- for (int ik = 0; ik < arrLine.Length; ik++) {
- print (arrLine [ik]);
- }
- arrLine [line_to_edit + 1] = "" + (playerX+2) + "," + playerY + "," + playerZ;
- File.WriteAllLines (path, arrLine);
- }
- /*}*/
- }
- private float t = 0;
- /*
- IEnumerator exitGame(){
- NetworkManager.singleton.client.Disconnect (); //THIS LEAVES BEHIND A GAMEOBJECT THAT SHOULDN'T BE THERE ?
- yield return new WaitForSeconds(1);
- Application.Quit (); //THIS WORKS BUT CAUSES A TIMEOUT
- yield return null;
- }
- */
- [Command]
- void CmdAnimateMove(){ //Client sends to server a request for animation to play
- m_Animator.animator.SetBool ("Weak_Attack", false);
- m_Animator.animator.SetBool ("WASD_pressed_to_move", true);
- RpcAnimateMove (); //that request gets passed and displayed to all clients
- }
- [ClientRpc]
- void RpcAnimateMove(){
- m_Animator.animator.SetBool ("Weak_Attack", false);
- m_Animator.animator.SetBool("WASD_pressed_to_move", true);
- }
- [Command]
- void CmdAnimateDontMove(){
- m_Animator.animator.SetBool ("Weak_Attack", false);
- m_Animator.animator.SetBool ("WASD_pressed_to_move", false);
- RpcAnimateDontMove ();
- }
- [Command]
- void CmdAnimateWkAttack(){
- m_Animator.animator.SetBool ("Weak_Attack", true);
- //m_Animator.animator.SetBool ("Weak_Attack", false);
- RpcAnimateWkAttack ();
- }
- [ClientRpc]
- void RpcAnimateWkAttack(){
- m_Animator.animator.SetBool ("Weak_Attack", true);
- //m_Animator.animator.SetBool ("Weak_Attack", false);
- }
- [ClientRpc]
- void RpcAnimateDontMove(){
- m_Animator.animator.SetBool ("Weak_Attack", false);
- m_Animator.animator.SetBool ("WASD_pressed_to_move", false);
- }
- [Command]
- void CmdStopMove(){
- m_Animator.animator.SetBool ("WASD_pressed_to_move", false);
- }
- private void Update()
- {
- //m_Animator.SetParameterAutoSend (0, true);
- //print (!isLocalPlayer);
- if (isServer) {
- playerCamera.SetActive (false);
- waterCameras.SetActive (false);
- }
- //THE USERNAME AND PASSWORD CANNOT BE THE SAME AS AN ALREADY EXISTING ONE. "TQT" as username, also cannot have "TQT" as password
- //Escape quits this game
- /*if (!isServer && Input.GetKey(KeyCode.Escape) && Input.GetKey(KeyCode.Q)) {
- //if(!isServer){
- //for(A FOR LOOP){
- // if (fileget() == DataToSendToGame.username) {
- // Line_of_the_username_in_the_file = <insert number here>;
- // }
- //}
- //string path = "Assets/Resources/test.txt";
- //static void lineChanger(string newText, string fileName . int line_to_edit) {
- string path = "Assets/Resources/test.txt";
- StreamReader reader = new StreamReader(path);
- string text2 = " ";
- int incrementing_counter = 0;
- bool nameFound = false;
- //MAKE THE FILE [USERNAME \n PASSWORD \n DATA \n USERNAME \n PASSWORD \n DATA \n etc... ]
- while (text2 != null) {
- incrementing_counter++;
- text2 = reader.ReadLine(); //Username
- if (text2 == DataToSendToGame.username) {
- Line_of_the_username_in_the_file = incrementing_counter;
- nameFound = true;
- }
- }
- reader.Close();
- int line_to_edit = Line_of_the_username_in_the_file; //THERE IS NO '0' INDEX
- if (nameFound == true) {
- string[] arrLine = File.ReadAllLines (path);
- arrLine [line_to_edit + 1] = "" + transform.position.x + "," + transform.position.y + "," + transform.position.z;
- File.WriteAllLines (path, arrLine);
- }
- NetworkManager.singleton.StopClient();
- //Application.Quit (); //if the password is wrong, crash!
- //}
- }*/
- //int Line_of_the_username_in_the_file = 0;
- //Escape quits this game
- if (Save_and_quit == true) {
- //if(!isServer){
- /*for(A FOR LOOP){
- if (fileget() == DataToSendToGame.username) {
- Line_of_the_username_in_the_file = <insert number here>;
- }
- }*/
- //Debug.Log ("OPIWNKEFMPJIL");
- if (!isServer) {
- CmdRecordData (transform.position.x, transform.position.y, transform.position.z, DataToSendToGame.username);
- }
- /*string path = "Assets/Resources/test.txt";
- System.IO.StreamReader reader = new System.IO.StreamReader (path);
- //static void lineChanger(string newText, string fileName . int line_to_edit) {
- //StreamReader reader = new StreamReader(path);
- string text2 = " ";
- int incrementing_counter = 0;
- bool nameFound = false;
- //MAKE THE FILE [USERNAME \n PASSWORD \n DATA \n USERNAME \n PASSWORD \n DATA \n etc... ]
- while (text2 != null) {
- incrementing_counter++;
- text2 = reader.ReadLine(); //Username, this needs to loop back to the file start
- if (text2 == DataToSendToGame.username) {
- Line_of_the_username_in_the_file = incrementing_counter;
- //AmmoText2.text = "q" + Line_of_the_username_in_the_file;
- nameFound = true;
- }
- }
- //end of reading
- //reader.DiscardBufferedData();
- reader.BaseStream.Position = 0; //Sets reader to start of file
- reader.Close();
- int line_to_edit = Line_of_the_username_in_the_file; //THERE IS NO '0' INDEX
- if (nameFound == true) {
- string[] arrLine = File.ReadAllLines (path);
- arrLine [line_to_edit + 1] = "" + (transform.position.x+5) + "," + transform.position.y + "," + transform.position.z;
- File.WriteAllLines (path, arrLine);
- }
- //}
- //line_to_edit = 0;
- //NetworkManager.singleton.StopClient();*/
- if(isLocalPlayer){
- //NetworkManager.Destroy (gameObject);\
- //THIS (THE COMMENTED OUT STUFF) PREVENTS THE TIMEOUT BUT DOES NOT SAVE THE DATA
- //Destroy(gameObject);
- //transform.position = new Vector3 (0, 0, 0);
- //NetworkManager.singleton.client.Disconnect (); //THIS LEAVES BEHIND A GAMEOBJECT THAT SHOULDN'T BE THERE ?
- //WaitForSeconds(1);
- Application.Quit (); //THIS WORKS BUT CAUSES A TIMEOUT -- ONLY FOR THE EDITOR -- FOR THE BUILD AND RUN AS SERVER IT IS FINE
- //StartCoroutine (exitGame());
- //NOT SURE IF THE BELOW LINE IS NECESSARY -- CAN'T TELL IF ON THE VM IF THE CLIENTS CAN CONNECT AFTER DISCONNECTING OR NOT
- //Application.Quit (); //if the password is wrong, crash!
- /*if (!isServer) {
- NetworkClient.ShutdownAll();
- //then destroy me
- Destroy(gameObject);
- }*/
- }
- //}
- //NetworkManager.singleton.StopClient();
- }
- if (!isLocalPlayer) {
- camera.enabled = false;
- canvas.SetActive (false);
- listener.enabled = false;
- //bulletSpawn.SetActive (false);
- //bulletSpawn2.SetActive (false);
- return;
- }
- //move everything left 1.
- if (Input.GetKeyDown (KeyCode.Mouse1)) { // THESE ARE LIKE FUNCTIONS
- string first = cards [0];
- for (int i = 0; i < 4; i++) {
- cards [i] = cards [i + 1];
- }
- cards [4] = first;
- book.text = "{ [" + cards[0] + "],[" + cards[1] + "],[" + cards[2] + "],[" + cards[3] + "],[" + cards[4] + "] }";
- }
- bool startfly = false;
- bool startparry = false;
- bool fireball = false;
- //left most becomes 'last'. Shift everything down by 1, new number enters the right
- // length = 0, 0 = 1, 1 = 2 etc...
- if (Input.GetKeyDown (KeyCode.Mouse0)) {
- first = cards [0];
- for (int i = 0; i < cards.Length; i++) {
- if (i == cards.Length - 1) {
- cards [i] = first;
- } else {
- 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.
- }
- }
- book.text = "{ [" + cards[0] + "],[" + cards[1] + "],[" + cards[2] + "],[" + cards[3] + "],[" + cards[4] + "] }";
- //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
- if(int.Parse(first) % 4 == 0){
- fireball = true;
- }else if (int.Parse(first) % 2 == 0) {
- startfly = true;
- } else {
- startparry = true;
- }
- waitTime3 = Time.time + float.Parse(first);
- }
- if (fireball || isSpellCasting) {
- isSpellCasting = true;
- string gun2 = "pistol"; //THIS MUST BE 'PISTOL' OR 'SHOTGUN' UNTIL NEW "SPELLS" ARE IMPLEMENTED
- string shooter2; //who is shooting
- // Debug.Log(playerSize2[1]);
- bool tempBool2 = true;
- bool breakingbool1 = true;
- //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
- if (Input.GetKeyDown (KeyCode.Mouse0)) {
- //printPlayers ();
- for (int i = 0; i < Health.players.Length; i++) {
- if (Health.players [i] == ((gameObject.GetComponent<NetworkIdentity> ().netId).ToString ())) {
- if (true /*Health.small_ammo [i] > 0*/) {
- shooter2 = (gameObject.GetComponent<NetworkIdentity> ().netId).ToString ();
- CmdFire (bulletSpawn.transform.position - bulletSpawn2.transform.position, bulletSpawn.transform.position, bulletSpawn.transform.rotation, gun2, shooter2);
- fireball = false;
- isSpellCasting = false;
- }
- }
- }
- } else if (Input.GetKeyDown (KeyCode.W) || Input.GetKeyDown (KeyCode.A) || Input.GetKeyDown (KeyCode.S) || Input.GetKeyDown (KeyCode.D)) {
- isSpellCasting = false;
- 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'
- }
- }
- if (gameObject.name == "large") {
- RpcLarge ();
- }
- if (startfly) {
- fly = true;
- }
- if (startparry) {
- parry = true;
- }
- if (fly) {
- this._rigidbody3d.useGravity = false; //REMOVE THIS LINE and it becomes like a 'high jump' -- which can be used as a card
- if (Input.GetKey (KeyCode.Space)) {
- transform.position = transform.position + (Camera.main.transform.up - (new Vector3(0f, Camera.main.transform.forward.y, 0f))) * _speed * Time.deltaTime;
- }
- if(Input.GetKey(KeyCode.LeftShift)){
- transform.position = transform.position - (Camera.main.transform.up - (new Vector3(0f, Camera.main.transform.forward.y, 0f))) * _speed * Time.deltaTime;
- }
- if (Time.time > waitTime3) {
- fly = false;
- //this._rigidbody3d.useGravity = true;
- }
- }
- if (parry) {
- //whatever parry is -- technically testing this is an 'experience', requires something to shoot at you, then you parry it.
- if (Time.time > waitTime3) {
- parry = false;
- }
- }
- Cursor.lockState = CursorLockMode.Locked;
- position = new Rect ((Screen.width - crosshair.width) / 2, (Screen.height - crosshair.height) / 2, crosshair.width, crosshair.height);
- //If the player is high up above the terrain, increase render distance
- if (gameObject.transform.position.y > 135f) {//current cutoff for high ground view is -20 [should see cities below and far into the ocean]
- camera.farClipPlane = 1500;
- } else {
- camera.farClipPlane = 800; //low ground [can't see far into the ocean]
- }
- RaycastHit hit;
- Ray ray = camera.ScreenPointToRay (Input.mousePosition);
- int temp_index = FindInPlayers ((gameObject.GetComponent<NetworkIdentity> ().netId).ToString ());
- //item0 is the compass
- if (Input.GetKeyDown (KeyCode.Alpha0)) {
- activeItem = Health.item0;
- items.text = "*0* 1 2 3 4 5 6 compass";
- }
- if (Input.GetKeyDown (KeyCode.Alpha1)) {
- activeItem = Health.item1;
- items.text = "0 *1* 2 3 4 5 6 " + Health.item1 [temp_index];
- }
- if (Input.GetKeyDown (KeyCode.Alpha2)) {
- activeItem = Health.item2;
- items.text = "0 1 *2* 3 4 5 6 " + Health.item2 [temp_index];
- }
- if (Input.GetKeyDown (KeyCode.Alpha3)) {
- activeItem = Health.item3;
- items.text = "0 1 2 *3* 4 5 6 " + Health.item3 [temp_index];
- }
- if (Input.GetKeyDown (KeyCode.Alpha4)) {
- activeItem = Health.item4;
- items.text = "0 1 2 3 *4* 5 6 " + Health.item4 [temp_index];
- }
- if (Input.GetKeyDown (KeyCode.Alpha5)) {
- activeItem = Health.item5;
- items.text = "0 1 2 3 4 *5* 6 " + Health.item5 [temp_index];
- }
- if (Input.GetKeyDown (KeyCode.Alpha6)) {
- activeItem = Health.item6;
- items.text = "0 1 2 3 4 5 *6* " + Health.item6 [temp_index];
- }
- LayerMask mask = LayerMask.GetMask ("PickUPS");
- //LIGHT MOVEMENT, SPAWN AT EACH PLAYER'S POSITION!!!! THIS WILL SPAWN IT AT THE PAD POSITIONS
- /*if (Time.time > waitTime2 + 0.5f && gameObject.activeInHierarchy) {
- var Clones = GameObject.FindGameObjectsWithTag ("Light2");//Destroy all solid light
- for (int i = 0; i < Clones.Length; i++) {
- Destroy (Clones [i]);
- }
- }
- //change the top if and if below by opposite operation to adjust lerping stats
- if (Time.time > waitTime2 + 0.5f && gameObject.activeInHierarchy && Time.time < waitTime2 + 2) {
- lerp = true;
- } else {
- lerp = false;
- }
- if (lerp) {
- t += 0.01f;
- var Clones = GameObject.FindGameObjectsWithTag ("Light");
- for (int i = 0; i < Clones.Length; i++){
- Clones [i].GetComponent<Renderer> ().material.color = Color.Lerp (Color.white, Color.clear, t);//lerp the transparent light
- //every frame the lerp gets 1% closer to 1. 0 -> 1, at 1 done lerping
- }
- }
- if(Time.time > waitTime2 + 1.25f && gameObject.activeInHierarchy){
- var Clones = GameObject.FindGameObjectsWithTag ("Light");
- for(int i = 0; i < Clones.Length; i++){
- Clones [i].transform.position += new Vector3 (0, 5, 0);
- if (Clones [i].transform.localScale.x > 0) {
- Clones [i].transform.localScale += new Vector3 (-0.05f, 0, -0.05f);
- }
- }
- }
- if(Time.time > waitTime2+5 && gameObject.activeInHierarchy){
- var Clones = GameObject.FindGameObjectsWithTag ("Light");
- for(int i = 0; i < Clones.Length; i++){
- Destroy (Clones [i]);
- }
- }*/
- //END OF LERPING
- //can't move during first 2 seconds
- if (Time.time < waitTime2 + 1) {
- return;
- }
- if (Physics.Raycast (ray, out hit, 10f, mask)) {
- Transform objectHit = hit.transform;
- // print (hit.transform.name);
- 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)) {
- if (Health.item1 [temp_index] == null) {
- Health.item1 [temp_index] = hit.transform.name;
- } else if (Health.item2 [temp_index] == null) {
- Health.item2 [temp_index] = hit.transform.name;
- } else if (Health.item3 [temp_index] == null) {
- Health.item3 [temp_index] = hit.transform.name;
- } else if (Health.item4 [temp_index] == null) {
- Health.item4 [temp_index] = hit.transform.name;
- } else if (Health.item5 [temp_index] == null) {
- Health.item5 [temp_index] = hit.transform.name;
- } else if (Health.item6 [temp_index] == null) {
- Health.item6 [temp_index] = hit.transform.name;
- } else {
- if (activeItem != Health.item0) {
- //drop the item, send it to server. Name the instantiated thing activeItem[temp_index] and give it PickUp tag.
- //CmdDrop (activeItem [temp_index]);
- for(int j = 0; j < 100; j++){
- if (Health.extra [temp_index, j] == null) {
- Health.extra [temp_index, j] = activeItem [temp_index];
- print (Health.extra [temp_index, j]);
- break;
- }
- }
- activeItem [temp_index] = hit.transform.name;
- }
- }
- if (isClient) {
- CmdDestroy (hit.transform.gameObject);
- }
- }
- }
- if (gameObject.GetComponent<Collider> ().enabled == false) {
- return;
- }
- /* 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]
- * LOOP THROUGH THAT ARRAY, IF THE NET ID OF THIS GAMEOBJECT MATCHES THEN THAT IS THE PLAYER THAT IS SHOOTING
- * 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
- * -> 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.
- * 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. */
- //THE ABOVE WILL NOT BE IMPLEMENTED, IT PROBABLY WILL NEVER AND SHOULD NEVER BE...
- string gun = activeItem[temp_index]; //what gun to use for the "fire" function. Default pistol
- string shooter; //who is shooting
- // Debug.Log(playerSize2[1]);
- bool tempBool = true;
- if (Input.GetKeyDown (KeyCode.Mouse0) && (gun == "pistol" || gun == "AR")) {
- //printPlayers ();
- for (int i = 0; i < Health.players.Length; i++) {
- if (Health.players [i] == ((gameObject.GetComponent<NetworkIdentity> ().netId).ToString ())) {
- if (true /*Health.small_ammo [i] > 0*/) {
- Health.small_ammo [i] -= 1;
- AmmoText.text = "S" + Health.small_ammo [i].ToString ();
- shooter = (gameObject.GetComponent<NetworkIdentity> ().netId).ToString ();
- CmdFire (bulletSpawn.transform.position - bulletSpawn2.transform.position, bulletSpawn.transform.position, bulletSpawn.transform.rotation, gun, shooter);
- break;
- }
- }
- }
- } else if (Input.GetKeyDown (KeyCode.Mouse0) && (gun == "Shotgun" || gun == "Rocket") && Time.time > waitTime && GetIndex() != 100 && playerSize2[GetIndex()] == "large") {
- //cooldown for shotgun is 1 seconds
- waitTime = Time.time + 1;
- for (int i = 0; i < Health.players.Length; i++) {
- if (Health.players [i] == ((gameObject.GetComponent<NetworkIdentity> ().netId).ToString ())) {
- if (true/*Health.small_ammo [i] > 0*/) {
- Health.small_ammo [i] -= 1;
- AmmoText.text = "S" + Health.small_ammo [i].ToString ();
- shooter = (gameObject.GetComponent<NetworkIdentity> ().netId).ToString ();
- CmdFire (bulletSpawn.transform.position - bulletSpawn2.transform.position, bulletSpawn.transform.position, bulletSpawn.transform.rotation, gun, shooter);
- break;
- }
- }
- }
- } else if (Input.GetKeyDown(KeyCode.Mouse0) && gun == "compass" && Time.time > waitTime){
- //cooldown for compass is 10 seconds
- waitTime = Time.time + 10;
- Drawline (transform.position, transform.rotation);
- }
- if (playerSize2[GetIndex()] == "large" && gameObject.GetComponent<MeshRenderer> ().enabled == true && Time.time > waitTime2 /*&& islocalplayer*/ ) {//this becomes true after 10 seconds
- CmdMeshLarge();//This disables the default for the large character, now do another if that makes a different mesh get rendered as "true"
- }
- if (playerSize2[GetIndex()] == "small" && gameObject.GetComponent<MeshRenderer> ().enabled == true && Time.time > waitTime2 /*&& isLocalplayer*/ ) {//this becomes true after 10 seconds
- CmdMeshSmall();//This disables the default for the large character, now do another if that makes a different mesh get rendered as "true"
- }
- //print (GameObject.FindGameObjectsWithTag ("Player").Length > numPlayers);
- if(GameObject.FindGameObjectsWithTag ("Player").Length > numPlayers){
- //THIS WORKS, JUST NEED AN IF CHECK SO THAT IT STOPS WHEN A PLAYER DIES
- if (isLocalPlayer && lifeGemNOTcritboxGem.activeInHierarchy == false) {
- if (playerSize2[GetIndex()] == "large") {
- CmdUpdateMeshLarge (); //send mesh to everyone so they see it right
- }
- }
- /*if (isLocalPlayer && lifeGemNOTcritboxGem.activeInHierarchy == true) {
- if (playerSize2[GetIndex()] == "large") {
- CmdRemoveMeshLarge (); //send mesh to everyone so they see it right
- }
- } */
- //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.
- //Something like a "die" function that sends a variable into here when a player dies so that it stops updating the models.
- if (isLocalPlayer && lifeGemNOTcritboxGem.activeInHierarchy == false) {
- if(playerSize2[GetIndex()] == "small"){
- CmdUpdateMeshSmall (); //send mesh to everyone so they see it right
- }
- }
- /*if (isLocalPlayer && lifeGemNOTcritboxGem.activeInHierarchy == true) {
- if(playerSize2[GetIndex()] == "small"){
- CmdRemoveMeshSmall (); //send mesh to everyone so they see it right
- }
- }*/
- numPlayers = GameObject.FindGameObjectsWithTag ("Player").Length;
- }
- //Camera Rotation THIS FOR SOME REASON DOESN'T SEEM TO BE NETWORKED
- y = Input.GetAxis("Mouse X");
- x = Input.GetAxis ("Mouse Y");
- rotateValue = new Vector3(x * (-1.0f)*(sensitivity), y * (sensitivity), 0);
- //print (transform.eulerAngles + "-" + rotateValue);
- if (rotationChecker.transform.eulerAngles.x < 340 && rotationChecker.transform.eulerAngles.x > 300) {
- rotationChecker.transform.eulerAngles = new Vector3(340, rotationChecker.transform.eulerAngles.y, rotationChecker.transform.eulerAngles.z);
- }
- if (rotationChecker.transform.eulerAngles.x > 45 && rotationChecker.transform.eulerAngles.x < 90) {
- rotationChecker.transform.eulerAngles = new Vector3(45, rotationChecker.transform.eulerAngles.y, rotationChecker.transform.eulerAngles.z);
- }
- rotationChecker.transform.eulerAngles = rotationChecker.transform.eulerAngles - rotateValue;
- //End of camera rotating
- //Diagonals -> It takes approxiamately 4 minutes to go from end to end horizontally of the map created.
- //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.
- if(Input.GetKeyDown (KeyCode.V)) {
- for (int i = 0; i < Health.players.Length; i++) {
- if (Health.players [i] == ((gameObject.GetComponent<NetworkIdentity> ().netId).ToString ())) {
- if (Time.time >= waitTime4) {
- //Health.small_ammo [i] -= 1;
- //AmmoText.text = "S" + Health.small_ammo [i].ToString ();
- shooter = (gameObject.GetComponent<NetworkIdentity> ().netId).ToString ();
- waitTime4 = Time.time + 1.0f;
- CmdAnimateWkAttack ();
- CmdFire (Vector3.up, gameObject.transform.position, gameObject.transform.rotation, "Weak_Attack", shooter);
- break;
- }
- }
- }
- } else if (Input.GetKey (KeyCode.W) && (Input.GetKey (KeyCode.A))) {
- transform.position = transform.position + (Camera.main.transform.forward - (new Vector3 (0f, Camera.main.transform.forward.y, 0f))) * (_speed / Mathf.Sqrt (2)) * Time.deltaTime;
- transform.position = transform.position - Camera.main.transform.right * (_speed / Mathf.Sqrt (2)) * Time.deltaTime;
- } else if (Input.GetKey (KeyCode.W) && (Input.GetKey (KeyCode.D))) {
- transform.position = transform.position + (Camera.main.transform.forward - (new Vector3 (0f, Camera.main.transform.forward.y, 0f))) * (_speed / Mathf.Sqrt (2)) * Time.deltaTime;
- transform.position = transform.position + Camera.main.transform.right * (_speed / Mathf.Sqrt (2)) * Time.deltaTime;
- } else if (Input.GetKey (KeyCode.S) && (Input.GetKey (KeyCode.A))) {
- transform.position = transform.position - (Camera.main.transform.forward - (new Vector3 (0f, Camera.main.transform.forward.y, 0f))) * (_speed / Mathf.Sqrt (2)) * Time.deltaTime;
- transform.position = transform.position - Camera.main.transform.right * (_speed / Mathf.Sqrt (2)) * Time.deltaTime;
- } else if (Input.GetKey (KeyCode.S) && (Input.GetKey (KeyCode.D))) {
- transform.position = transform.position - (Camera.main.transform.forward - (new Vector3 (0f, Camera.main.transform.forward.y, 0f))) * (_speed / Mathf.Sqrt (2)) * Time.deltaTime;
- transform.position = transform.position + Camera.main.transform.right * (_speed / Mathf.Sqrt (2)) * Time.deltaTime;
- }
- //single key
- else if (Input.GetKey (KeyCode.W)) {
- transform.position = transform.position + (Camera.main.transform.forward - (new Vector3 (0f, Camera.main.transform.forward.y, 0f))) * _speed * Time.deltaTime;
- if(!(Input.GetKey(KeyCode.V))){
- CmdAnimateMove (); //m_Animator.animator.SetBool ("WASD_pressed_to_move", true);
- }
- //isWalk = true;
- } else if (Input.GetKey (KeyCode.S)) {
- transform.position = transform.position - (Camera.main.transform.forward - (new Vector3 (0f, Camera.main.transform.forward.y, 0f))) * _speed * Time.deltaTime;
- if(!(Input.GetKey(KeyCode.V))){
- CmdAnimateMove (); //m_Animator.animator.SetBool ("WASD_pressed_to_move", true);
- }
- } else if (Input.GetKey (KeyCode.A)) {
- transform.position = transform.position - Camera.main.transform.right * _speed * Time.deltaTime;
- if(!(Input.GetKey(KeyCode.V))){
- CmdAnimateMove (); //m_Animator.animator.SetBool ("WASD_pressed_to_move", true);
- }
- } else if (Input.GetKey (KeyCode.D)) {
- transform.position = transform.position + Camera.main.transform.right * _speed * Time.deltaTime;
- if(!(Input.GetKey(KeyCode.V))){
- CmdAnimateMove (); //m_Animator.animator.SetBool ("WASD_pressed_to_move", true);
- }
- } else { //no key is pressed
- if (!(Input.GetKey (KeyCode.V))) {
- CmdAnimateDontMove ();
- }
- //m_Animator.animator.SetBool ("WASD_pressed_to_move", false);
- //m_Animator.Stop
- //isWalk = false;
- }
- //if (isWalk == true && !(The_animator == null)) {
- // The_animator.SetBool ("WASD_pressed_to_move", true);
- //} else if (isWalk == false && !(The_animator == null)) {
- // The_animator.SetBool ("WASD_pressed_to_move", false);
- //}
- // other moving
- // _rigidbody3d.AddForce(
- // NaturalMovement.MatchVelocityForce(
- // new Vector3(
- // (transform.right * Input.GetAxis("Horizontal")).x,
- // 0.0f,
- // (transform.forward * Input.GetAxis("Vertical")).z) * _maxVelocity,
- // new Vector3(_rigidbody3d.velocity.x, 0.0f, _rigidbody3d.velocity.z),
- // _acceleration,
- // _maxAcceleration));
- //if the jump is higher than the max velocity then it equals the max
- if (_rigidbody3d.velocity.y > _maxVelocity) {
- _rigidbody3d.velocity = new Vector3 (_rigidbody3d.velocity.x, _maxVelocity, _rigidbody3d.velocity.z);
- }
- //If the player is floating then give it a small velocity so that the if will detect and prevent it.
- if (_rigidbody3d.velocity.y == 0) {
- _rigidbody3d.velocity = new Vector3 (_rigidbody3d.velocity.x, 0.003f, _rigidbody3d.velocity.z);
- }
- //previous jump controller || (_rigidbody3d.velocity.y >= 0 && _rigidbody3d.velocity.y <= 0.01)
- if (Input.GetKeyDown (KeyCode.Space)) {
- Vector3 dwn = transform.TransformDirection (Vector3.down);
- //raycasts are nice because they take care of the ramp problem, also use raycasts for realistic platforming!!!
- if (Physics.Raycast (transform.position, dwn, 1.5f)){
- //_rigidbody3d.velocity = new Vector3 (_rigidbody3d.velocity.x, _jumpVelocity, _rigidbody3d.velocity.z)
- //instead of the weird velocity thing just add an impulse
- //_rigidbody3d.AddForce (new Vector3 (0, _jumpVelocity, 0), ForceMode.Impulse);
- //THESE ARE 0 AND NEED TO BE FIXED, REMEMBER THE JUMPVELOCITY SHOULD INCREASE AS XY-PLANE MOVEMENT INCREASES
- //print(_rigidbody3d.velocity.x);
- //print (_rigidbody3d.velocity.z); //CHANGE THIS VALUE (the 4f) FOR JUMP HEIGHT
- _rigidbody3d.velocity = (new Vector3 (_rigidbody3d.velocity.x, _jumpVelocity*4f, _rigidbody3d.velocity.z));
- } //else {
- //print ("There is nothing below the object!");
- //}
- }
- /*if (_rigidbody3d.velocity.y > -0.02 && _rigidbody3d.velocity.y <= 0.001) {
- _rigidbody3d.velocity = new Vector3 (_rigidbody3d.velocity.x, 0, _rigidbody3d.velocity.z);
- _rigidbody3d.useGravity = false;
- } else {
- _rigidbody3d.useGravity = true;
- //_rigidbody3d.velocity = new Vector3 (_rigidbody3d.velocity.x, 1, _rigidbody3d.velocity.z);
- }*/
- // Falling
- if (_rigidbody3d.velocity.y < 0){ //CHANGE THIS VALUE FOR GRAVITY
- _rigidbody3d.velocity += Vector3.up * Physics.gravity.y * 1.5f*4f * Time.deltaTime;
- }
- }
- private void FixedUpdate()
- {
- _rigidbody3d.velocity = new Vector3(
- NaturalMovement.CapVelocity(new Vector3(_rigidbody3d.velocity.x, 0.0f, _rigidbody3d.velocity.z), _maxVelocity).x,
- _rigidbody3d.velocity.y, NaturalMovement.CapVelocity(new Vector3(_rigidbody3d.velocity.x, 0.0f, _rigidbody3d.velocity.z), _maxVelocity).z);
- }
- //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
- public int FindInPlayers(string playerID){
- for (int i = 0; i < Health.players.Length; i++) {
- if (Health.players [i] == playerID) {
- return i;
- }
- }
- return 0;
- }
- //also placed into all scripts
- void printPlayers(){
- for (int i = 0; i < Health.players.Length; i++) {
- Debug.Log (Health.players [i]);
- }
- }
- [Command]
- void CmdFire(Vector3 Direction, Vector3 bulletPosition, Quaternion bulletRotation, string gun, string shooter)
- {
- //use the shooter passed into here to record who shot the bullet and who was hit other.GetComponent<NetworkIdentity>().netID is the other person
- if (gun == "pistol") {
- // Create the Bullet from the Bullet Prefab
- var bullet = (GameObject)Instantiate (
- bulletPrefab,
- bulletPosition,
- bulletRotation);
- //Ignore these two lines, they assign the shooter to the bullet for KDA purposes... which are not important for the demo.
- bullet.name = shooter;//ONLY ON THE SERVER!!
- GiveBulletName (bullet, shooter);
- //print ("bullet" + transform.name);
- //bullet.transform.parent = gameObject.transform;
- bullet.GetComponent<Rigidbody> ().velocity = Direction.normalized * 60;
- //print (rotationChecker.transform.rotation.eulerAngles); //position and rotation for each player can be tracked easily as data.
- NetworkServer.Spawn (bullet);
- // Destroy the bullet after 2 seconds
- StartCoroutine (despawnBullet (bullet));
- } else if (gun == "Shotgun") {
- // Create the Bullet from the Bullet Prefab
- var bullet = (GameObject)Instantiate (
- ShotgunBulletPrefab,
- bulletPosition,
- bulletRotation);
- //Ignore these two lines, they assign the shooter to the bullet for KDA purposes... which are not important for the demo.
- bullet.name = shooter;
- GiveBulletName (bullet, shooter);
- //print ("bullet" + transform.name);
- //bullet.transform.parent = gameObject.transform;
- bullet.GetComponent<Rigidbody> ().velocity = Direction.normalized * 60;
- //print (rotationChecker.transform.rotation.eulerAngles); //position and rotation for each player can be tracked easily as data.
- NetworkServer.Spawn (bullet);
- // Destroy the bullet after 2 seconds
- StartCoroutine (despawnBullet (bullet));
- } else if (gun == "Weak_Attack") {
- var bullet = (GameObject)Instantiate (
- WeakBulletPrefab,
- bulletPosition,
- bulletRotation);
- //Ignore these two lines, they assign the shooter to the bullet for KDA purposes... which are not important for the demo.
- bullet.name = shooter;
- GiveBulletName (bullet, shooter);
- //print ("bullet" + transform.name);
- //bullet.transform.parent = gameObject.transform;
- bullet.GetComponent<Rigidbody> ().velocity = Direction.normalized * 0;
- //print (rotationChecker.transform.rotation.eulerAngles); //position and rotation for each player can be tracked easily as data.
- NetworkServer.Spawn (bullet);
- // Destroy the bullet after 2 seconds
- StartCoroutine (despawnWeakAttack (bullet));
- }
- }
- [Command]
- void CmdDestroy(GameObject obj){
- Destroy (obj);
- }
- void GiveBulletName(GameObject bullet, string shooter){
- bullet.name = shooter;
- }
- void Drawline (Vector3 bulletPosition, Quaternion bulletRotation){
- float disClosest = Mathf.Infinity;
- Health enemyClosest = null;
- Health[] allEnemies = GameObject.FindObjectsOfType<Health> ();
- foreach (Health currentEnemy in allEnemies) {
- float distanceTo = (currentEnemy.transform.position - this.transform.position).sqrMagnitude;
- if (distanceTo < disClosest && distanceTo > 1.5f) {
- disClosest = distanceTo;
- enemyClosest = currentEnemy;
- }
- }
- if (enemyClosest != null) {
- //if there is an enemy that can be tracked then...
- StartCoroutine(spawnTrackingBullets (bulletPosition, bulletRotation, enemyClosest));
- }
- }
- IEnumerator spawnTrackingBullets(Vector3 bulletPosition, Quaternion bulletRotation, Health enemyClosest){
- int counter = 0;
- while (counter < 30) {
- var bullet = (GameObject)Instantiate (
- CompassBulletPrefab,
- bulletPosition,
- bulletRotation);
- Vector3 directionTo = enemyClosest.transform.position - transform.position;
- bullet.GetComponent<Rigidbody> ().velocity = directionTo.normalized * 20;
- //Instantiate (bullet);
- StartCoroutine (despawnNonServerBullet (bullet));
- //because counter += 3 was not working...
- counter++;
- counter++;
- counter++;
- yield return new WaitForSeconds (0.25f);
- }
- }
- IEnumerator despawnBullet(GameObject bullet){
- yield return new WaitForSeconds (2.0f);
- NetworkServer.Destroy (bullet);
- }
- IEnumerator despawnWeakAttack(GameObject bullet){
- yield return new WaitForSeconds (0.7f);
- NetworkServer.Destroy (bullet);
- }
- int GetIndex(){
- for (int i = 0; i < Health.players.Length; i++) {
- if (Health.players [i] == (gameObject.GetComponent<NetworkIdentity> ().netId).ToString ()) {
- return i;
- }
- }
- return 100;
- }
- IEnumerator despawnNonServerBullet(GameObject bullet){
- yield return new WaitForSeconds (2.5f);
- Destroy (bullet);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement