// Update is called once per frame void Update() { if (!isLocalPlayer) { return; } else { if (cam.enabled == false) { cam.enabled = true; } if (audioListener.enabled == false) { audioListener.enabled = true; } lightcomp.intensity = lightIntensity; } Physics.Raycast(cam.transform.position, cam.transform.TransformDirection(Vector3.forward), out rayHit, 1.5f); //Debug.Log(rayHit.transform.gameObject); try { targetScript = rayHit.collider.gameObject.GetComponentInParent <Interactable>(); } catch (NullReferenceException) { interactionText.text = ""; interactionText.enabled = false; targetScript = null; //Debug.Log("No interaction script found."); } finally { if (!(targetScript == null)) { interactionText.text = targetScript.displayOnHover; interactionText.enabled = true; //Debug.Log(targetScript.gameObject); } else { interactionText.text = ""; interactionText.enabled = false; } } /* * if (!(targetScript == null)) * { * interactionText.text = targetScript.displayOnHover; * interactionText.enabled = true; * //Debug.Log(targetScript.gameObject); * } * else * { * interactionText.text = ""; * interactionText.enabled = false; * //Debug.Log("No interaction script found."); * } * //*/ //Check if ded if (health <= 0) { try { int spawnPointIndex = UnityEngine.Random.Range(0, spawns.Length); Vector3 spawnPoint = spawns[spawnPointIndex].transform.position; CmdRespawn(gameObject, spawnPoint); targetScript.UnsetUser(gameObject); } catch { return; } /* * Debug.Log(spawns.Count); * int spawnPointIndex = UnityEngine.Random.Range(0, spawns.Count); * Vector3 spawnPoint = spawns[spawnPointIndex].position; * CmdRespawn(gameObject, spawnPoint); * Debug.Log("Respawning Player"); * //*/ } //UI healthText.text = health.ToString(); magText.text = gameObject.GetComponent <WeaponController>().mag + "/" + gameObject.GetComponent <WeaponController>().magCap; reserveText.text = gameObject.GetComponent <WeaponController>().spareAmmo.ToString(); //Movement if (Input.GetKey(KeyCode.RightShift) | Input.GetKey(KeyCode.LeftShift)) { speed = moveSpeed * sprintMultiplier; } else { speed = moveSpeed; } if (!UIenabled) { rotY += Input.GetAxis("Mouse X") * sensitivity; float horizontalMovement = Input.GetAxis("Horizontal") * speed * Time.deltaTime; float verticalMovement = Input.GetAxis("Vertical") * speed * Time.deltaTime; if (movementLock == false) { transform.Translate(horizontalMovement, 0, verticalMovement); transform.eulerAngles = new Vector3(0, rotY, 0); } if (canJump == true & Time.time > lastJump + jumpDelay) { float jumpMovement = Input.GetAxis("Jump") * jumpHight; RigidBody.AddForce(0, jumpMovement, 0, ForceMode.Impulse); lastJump = Time.time; } if (cameraLock == false) { rotX += Input.GetAxis("Mouse Y") * sensitivity; rotX = Mathf.Clamp(rotX, -90, 90); cam.transform.eulerAngles = new Vector3(-rotX, rotY, 0); } } //cam.transform.position += cam.transform.up * Mathf.Sin(Time.time * 2f) * 0.001f; //Flashlight if (Input.GetKey("f")) { if (fHeld == false) { fHeld = true; if (lightcomp.intensity == 0) { lightIntensity = 5; } else { lightIntensity = 0; } CmdToggleFlashlight(gameObject); } } else { fHeld = false; } if (Input.GetKey("p") & pHeld == false) { { //Todo: Try using a cooldown instead. int spawnPointIndex = UnityEngine.Random.Range(0, spawns.Length); Vector3 spawnPoint = spawns[spawnPointIndex].transform.position; CmdRespawn(gameObject, spawnPoint); try { targetScript.UnsetUser(gameObject); } catch { return; } pHeld = true; } } if (!Input.GetKey("p")) { pHeld = false; } if (Input.GetKey(KeyCode.Escape) & escHeld == false) { if (!UIenabled) { pauseScript.openPauseMenu(); UIenabled = true; } else { pauseScript.closePauseMenu(); UIenabled = false; } escHeld = true; } if (!Input.GetKey(KeyCode.Escape)) { escHeld = false; } //* if (Input.GetKey("q") & qHeld == false) { qHeld = true; switch (character) { case "Turret": { if (buildableSpawned) { if (targetScript != null && targetScript.GetType().Name == "TurretScript") { buildableSpawned = false; despawnBuildable(turret); } } else { bool hitCollider = Physics.Raycast(cam.transform.position, cam.transform.TransformDirection(Vector3.forward), out rayHit, 5f); if (hitCollider) { if (Vector3.Angle(rayHit.normal, Vector3.up) == 0) { CmdPlaceBuildable(rayHit.point, rayHit.normal); buildableSpawned = true; } } } return; } case "Crate": { if (buildableSpawned) { if (targetScript != null && targetScript.GetType().Name == "CrateScript") { CrateScript targetScript = (CrateScript)gameObject.GetComponent <PlayerController>().targetScript; if (!targetScript.onCooldown) { buildableSpawned = false; despawnBuildable(turret); } } } else { bool hitCollider = Physics.Raycast(cam.transform.position, cam.transform.TransformDirection(Vector3.forward), out rayHit, 5f); if (hitCollider) { if (Vector3.Angle(rayHit.normal, Vector3.up) == 0) { CmdPlaceBuildable(rayHit.point, rayHit.normal); buildableSpawned = true; } } } return; } case "Medkit": { if (buildableSpawned) { } return; } default: { return; } } } if (!Input.GetKey("q")) { qHeld = false; } //*/ if (Input.GetKey("e") & targetScript != null & eHeld == false) { eHeld = true; targetScript.OnUse(gameObject); //CmdGiveAuthority(targetScript.gameObject); } if (Input.GetKey("e") == false) { eHeld = false; } }