private void Update() { bool shift = Input.GetKey(KeyCode.LeftShift); if ((Input.GetMouseButtonDown(0) && !shift) || (Input.GetMouseButton(0) && shift)) { if (UseGPURaycast) { Vector2 uv = Vector2.zero; uv.x = Input.mousePosition.x / RaycastCamera.pixelWidth; uv.y = Input.mousePosition.y / RaycastCamera.pixelHeight; bool isHitted = GPURaycast.RaycastToRegisteredTargets(RaycastCamera, uv, out hitInfo); if (isHitted) { DecalReceiverHelper.SendGPURaycastInfo(hitInfo); } } else { Ray r = RaycastCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (Physics.Raycast(r, out hitInfo)) { DecalReceiverHelper.SendPhysicsRaycastInfo(hitInfo); } } } }
protected virtual void shot(int button) { if (button == 0) { handsAnimator.Play("Shot", 0, 0); if (UseGPURaycast) { GPURaycastDecalsTargetInfo hitInfo; if (GPURaycast.RaycastToRegisteredTargets(Camera.main, Vector2.one / 2, out hitInfo)) { var hittable = hitInfo.hittedRenderer.GetComponent <Hittable>(); if (hittable != null) { DamageDataGPURaycast damage = new DamageDataGPURaycast() { DamageAmount = Damage, HitInfo = hitInfo }; hittable.TakeDamage(damage); } DecalReceiverHelper.SendGPURaycastInfo(hitInfo); } } else { Ray r = new Ray(Camera.main.transform.position, Camera.main.transform.forward); RaycastHit hitInfo; if (Physics.Raycast(r, out hitInfo, 1000, ShotMask)) { var hittable = hitInfo.collider.GetComponent <Hittable>(); if (hittable != null) { DamageDataPhysics damage = new DamageDataPhysics() { DamageAmount = Damage, HitInfo = hitInfo }; hittable.TakeDamage(damage); } DecalReceiverHelper.SendPhysicsRaycastInfo(hitInfo); } } } else if (button == 2) { handsAnimator.Play("Shot", 0, 0); GameObject projectileInstance = Instantiate(ProjectilePrefab, ProjectilePrefab.transform.position, ProjectilePrefab.transform.rotation); projectileInstance.transform.SetParent(null); projectileInstance.gameObject.SetActive(true); } }