private void OnTriggerEnter(Collider other) { // Player picks up the pickup if (other.transform.root.CompareTag("Player")) { GrantPickup(other.transform.root.gameObject); //Send a message to the server that the pickup was taken RequestPickup requestPickup = new RequestPickup(); requestPickup.setPickupName(this.gameObject.name); requestPickup.send(); connectionManager.send(requestPickup); } }
// Update is called once per frame void Update() { //Debug.DrawRay(this.transform.position, this.transform.forward * maxDistance, Color.magenta); //Gizmos.DrawWireSphere(this.transform.position + this.transform.forward * maxDistance, sphereRadius); RaycastHit hit; if (Physics.SphereCast(this.transform.position, sphereRadius, this.transform.forward, out hit, maxDistance) && hit.collider.gameObject.tag == "Medpack") { medAnim = hit.collider.gameObject.GetComponent <Animator>(); medAnim.enabled = true; currentHitDistance = hit.distance; counter.InteractHint(); if (Input.GetKeyDown(KeyCode.E)) { RequestPickup pickup = new RequestPickup(); pickup.setPickupName(hit.collider.gameObject.name); pickup.send(); Main.GetConnectionManager().send(pickup); Destroy(hit.collider.gameObject); counter.MedCounter(1); } } else { currentHitDistance = maxDistance; } if (Physics.SphereCast(this.transform.position, sphereRadius, this.transform.forward, out hit, maxDistance) && hit.collider.gameObject.tag == "Ammo") { ammoAnim = hit.collider.gameObject.GetComponent <Animator>(); ammoAnim.enabled = true; currentHitDistance = hit.distance; counter.InteractHint(); if (Input.GetKeyDown(KeyCode.E)) { RequestPickup pickup = new RequestPickup(); pickup.setPickupName(hit.collider.gameObject.name); pickup.send(); Main.GetConnectionManager().send(pickup); Destroy(hit.collider.gameObject); counter.AmmoPickup(); } } else { currentHitDistance = maxDistance; } if (Physics.SphereCast(this.transform.position, sphereRadius, this.transform.forward, out hit, maxDistance) && hit.collider.gameObject.tag == "Pistol") { currentHitDistance = hit.distance; counter.InteractHint(); if (Input.GetKeyDown(KeyCode.E)) { RequestPickup pickup = new RequestPickup(); pickup.setPickupName(hit.collider.gameObject.name); pickup.send(); Main.GetConnectionManager().send(pickup); list.heldGuns.Add(hit.collider.gameObject); hit.collider.gameObject.SetActive(false); //Destroy(hit.collider.gameObject); } } else { currentHitDistance = maxDistance; } if (Physics.SphereCast(this.transform.position, sphereRadius, this.transform.forward, out hit, maxDistance) && hit.collider.gameObject.tag == "Shotgun") { currentHitDistance = hit.distance; counter.InteractHint(); if (Input.GetKeyDown(KeyCode.E)) { RequestPickup pickup = new RequestPickup(); pickup.setPickupName(hit.collider.gameObject.name); pickup.send(); Main.GetConnectionManager().send(pickup); list.heldGuns.Add(hit.collider.gameObject); hit.collider.gameObject.SetActive(false); //Destroy(hit.collider.gameObject); } } else { currentHitDistance = maxDistance; } if (Physics.SphereCast(this.transform.position, sphereRadius, this.transform.forward, out hit, maxDistance) && hit.collider.gameObject.tag == "AK-47") { currentHitDistance = hit.distance; counter.InteractHint(); if (Input.GetKeyDown(KeyCode.E)) { RequestPickup pickup = new RequestPickup(); pickup.setPickupName(hit.collider.gameObject.name); pickup.send(); Main.GetConnectionManager().send(pickup); list.heldGuns.Add(hit.collider.gameObject); hit.collider.gameObject.SetActive(false); //Destroy(hit.collider.gameObject); } } else { currentHitDistance = maxDistance; } if (Physics.SphereCast(this.transform.position, sphereRadius, this.transform.forward, out hit, maxDistance) && hit.collider.gameObject.tag == "CarKey") { //Debug.Log("Raycast hit keys"); currentHitDistance = hit.distance; counter.InteractHint(); if (Input.GetKeyDown(KeyCode.E)) { RequestPickup pickup = new RequestPickup(); pickup.setPickupName(hit.collider.gameObject.name); pickup.send(); Main.GetConnectionManager().send(pickup); counter.hasKeys = true; //Debug.Log("Interact keys"); //list.heldGuns.Add(hit.collider.gameObject); hit.collider.gameObject.SetActive(false); //Destroy(hit.collider.gameObject); } } else { currentHitDistance = maxDistance; } if (Physics.SphereCast(this.transform.position, sphereRadius, this.transform.forward, out hit, maxDistance) && hit.collider.gameObject.tag == "Gas") { //Debug.Log("Raycast hit gas"); currentHitDistance = hit.distance; counter.InteractHint(); if (Input.GetKeyDown(KeyCode.E)) { RequestPickup pickup = new RequestPickup(); pickup.setPickupName(hit.collider.gameObject.name); pickup.send(); Main.GetConnectionManager().send(pickup); counter.hasGas = true; //Debug.Log("Interact gas"); //list.heldGuns.Add(hit.collider.gameObject); hit.collider.gameObject.SetActive(false); //Destroy(hit.collider.gameObject); } } else { currentHitDistance = maxDistance; } if (Physics.SphereCast(this.transform.position, sphereRadius, this.transform.forward, out hit, maxDistance) && hit.collider.gameObject.tag == "SteeringWheel") { //Debug.Log("Raycast hit steering wheel"); currentHitDistance = hit.distance; counter.InteractHint(); if (Input.GetKeyDown(KeyCode.E)) { RequestPickup pickup = new RequestPickup(); pickup.setPickupName(hit.collider.gameObject.name); pickup.send(); Main.GetConnectionManager().send(pickup); counter.hasSteeringWheel = true; //Debug.Log("Interact steering wheel"); //list.heldGuns.Add(hit.collider.gameObject); hit.collider.gameObject.SetActive(false); //Destroy(hit.collider.gameObject); } } else { currentHitDistance = maxDistance; } }