private void Handle(Vector3 contactPoint, TactSender tactSender) { if (tactSender != null) { var targetCollider = GetComponent <Collider>(); tactSender.Play(PositionTag, contactPoint, targetCollider); } }
public void ReflectHandle(Vector3 contactPoint, TactSender tactSender) { if (tactSender != null) { var targetCollider = GetComponent <Collider>(); contactPoint += new Vector3(0f, 0f, (targetCollider.transform.position.z - contactPoint.z) * 2f); tactSender.Play(PositionTag, contactPoint, targetCollider); } }
private void ShootPlayer() { if (Input.GetKeyDown(KeyCode.T)) { IsRaycastingShooting = !IsRaycastingShooting; if (IsRaycastingShooting) { lineRenderer.startWidth = 0.02f; lineRenderer.endWidth = 0.1f; } else { lineRenderer.startWidth = 0; lineRenderer.endWidth = 0; } } if (IsRaycastingShooting) { lineRenderer.SetPosition(0, shootingPoint.position); Vector3 endPosition = shootingPoint.position + (10 * shootingPoint.forward); lineRenderer.SetPosition(1, endPosition); } if (Input.GetMouseButtonDown(0)) { if (tactSender != null) { tactSender.Play(PositionTag.LeftArm); tactSender.Play(PositionTag.RightArm); } if (IsRaycastingShooting) { var targetPosition = shootingPoint.position; var direction = shootingPoint.forward; var length = 10f; Ray ray = new Ray(targetPosition, direction); RaycastHit raycastHit; Vector3 endPosition = targetPosition + (length * direction); lineRenderer.SetPosition(1, endPosition); if (Physics.Raycast(ray, out raycastHit, length)) { var detect = raycastHit.collider.gameObject.GetComponent <TactReceiver>(); var pos = PositionTag.Default; if (detect == null) { ///// THIS IS ONLY FOR DEMO CASE. var custom = raycastHit.collider.gameObject.GetComponent <BhapticsCustomTactReceiver>(); if (custom != null) { custom.ReflectHandle(raycastHit.point, tactSender); return; } } else { pos = detect.PositionTag; } if (tactSender != null) { tactSender.Play(pos, raycastHit); } } } else { var bullet = (GameObject)Instantiate(bulletPrefab, shootingPoint.transform.position, shootingPoint.transform.rotation); bullet.GetComponent <Rigidbody>().velocity = shootingPoint.forward * 10f; Destroy(bullet, 5f); } } }