void Awake() { if (arcRenderer == null) { arcRenderer = GetComponent <LineRenderer> (); } if (arcRaycaster == null) { arcRaycaster = GetComponent <ParabolicRaycaster> (); } else if (!(arcRaycaster is ParabolicRaycaster)) { Debug.LogError("ParabolicVisualizer's Arc Ray is not ParabolicRaycaster"); } if (arcRenderer == null) { Debug.LogError("ParabolicVisualizer's Line Renderer is not set"); } if (arcRaycaster == null) { Debug.LogError("ParabolicVisualizer's Arc Ray Caster is not set"); } if (segments < 3) { segments = 3; Debug.LogWarning("Should have at least 3 segments!"); } arcRenderer.positionCount = segments; if (arcRaycaster != null) { raycaster = arcRaycaster as ParabolicRaycaster; } }
void Start() { beamRenderer = GetComponent <LineRenderer>(); raycaster = GetComponent <ParabolicRaycaster>(); if (targetMarkerPrefab != null) { targetMarker = Instantiate(targetMarkerPrefab, Vector3.zero, Quaternion.identity) as GameObject; targetMarker.transform.SetParent(transform); targetMarker.SetActive(false); } }
private void RaycastBeam() { Ray beamRay = new Ray(transform.position, transform.forward); RaycastHit beamHit; if (raycaster.ParabolicRaycast(out beamHit, transform.position, transform.eulerAngles, raycastTravelDistance, raycastVelocity, raycastSegments)) { beamRenderer.enabled = true; beamRenderer.SetVertexCount(raycastSegments + 2); beamRenderer.SetPositions(ParabolicRaycaster.ParabolicPointsList(transform.position, transform.eulerAngles, beamHit.distance, raycastVelocity, raycastSegments)); beamRenderer.SetPosition(raycastSegments + 1, hitPosition); if (beamHit.normal.y > 0.01f) //If the surface has a positive slope { hitPosition = beamHit.point; validTeleport = true; PlaceTargetMarker(hitPosition, beamHit.normal); } else { hitPosition = beamHit.point; validTeleport = false; RemoveTargetMarker(); //Draw an invalid teleport marker } } else { beamRenderer.enabled = false; hitPosition = Vector3.zero; validTeleport = false; RemoveTargetMarker(); } }