// Update is called once per frame void Update() { // Check for object hit by reflected ray RaycastHit reflectedHitInfo; // Render the transmimssion //mirrorTransmission.SetPositions(this.transform.position, satellite.transform.position); bool objectWasHit = Physics.Raycast(transform.position, emitDirection, out reflectedHitInfo, MAX_TRANSMISSION_DISTANCE); // If an object was hit and it wasn't this planet if (objectWasHit /*&& reflectedHitInfo.collider.gameObject != this.gameObject*/) { mirrorTransmission.SetPositions(this.transform.position, reflectedHitInfo.point); // Try to get its TransmissionReceiverComponent and call its ReceiveTransmission function TransmissionReceiverComponent receiverComponent = reflectedHitInfo.collider.GetComponent <TransmissionReceiverComponent>(); if (receiverComponent != null && receiverComponent.state != TransmissionReceiverComponent.ReceiverState.ACTIVATED) { receiverComponent.ReceiveTransmission(); } } else { mirrorTransmission.SetPositions(this.transform.position, this.transform.position + (emitDirection * 500f)); } // For debugging to visualize the physics rays //Debug.DrawRay(this.transform.position, dirReflectOffMirror, Color.green); Debug.DrawRay(transform.position, emitDirection * MAX_TRANSMISSION_DISTANCE, Color.green); }
// Update is called once per frame void Update() { // Calculate the direction from this planet to it's coupled satellite dirToSatellite = satellite.transform.position - this.transform.position; // Calculate the direction of the ray reflected off the satellite using its normal RaycastHit satelliteHitInfo; Physics.Raycast(this.transform.position, dirToSatellite, out satelliteHitInfo); dirReflectOffSatellite = Vector3.Reflect(dirToSatellite, satelliteHitInfo.normal).normalized; // Render the transmimssion planetTransmission.SetPositions(this.transform.position, satellite.transform.position); // Check for object hit by reflected ray RaycastHit reflectedHitInfo; bool objectWasHit = Physics.Raycast(satellite.transform.position, dirReflectOffSatellite, out reflectedHitInfo, MAX_TRANSMISSION_DISTANCE); // If an object was hit and it wasn't this planet if (objectWasHit) { satelliteTransmission.SetPositions(satellite.transform.position, reflectedHitInfo.point); if (currentReceiver != null && reflectedHitInfo.collider.gameObject != currentReceiver.gameObject) { currentReceiver.TransmissionExit(); currentReceiver = null; } if (reflectedHitInfo.collider.gameObject != this.gameObject) { // Try to get its TransmissionReceiverComponent and call its ReceiveTransmission function TransmissionReceiverComponent receiverComponent = reflectedHitInfo.collider.GetComponent <TransmissionReceiverComponent>(); if (receiverComponent != null) { receiverComponent.TransmissionEnter(); currentReceiver = receiverComponent; } } } else { satelliteTransmission.SetPositions(satellite.transform.position, satellite.transform.position + (dirReflectOffSatellite * 500f)); if (currentReceiver != null) { currentReceiver.TransmissionExit(); currentReceiver = null; } } }