void ShowPreview() { previewing = true; GOPreview = new GameObject(); foreach (CameraPoint CP in CamPoints) { GameObject NewSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); NewSphere.transform.position = CP.pos; NewSphere.transform.rotation = CP.rot; NewSphere.transform.localScale = NewSphere.transform.localScale / 2; NewSphere.transform.SetParent(GOPreview.transform); } //Smooth Curve SetSmoothCamPoints(); LineRenderer LR; if (gameObject.GetComponent <LineRenderer>()) { LR = gameObject.GetComponent <LineRenderer>(); } else { LR = GOPreview.AddComponent <LineRenderer>(); LR.SetWidth(.2f, .2f); LR.useWorldSpace = true; LR.material = AssetManager.Instance.dataViewMaterial; } LR.SetVertexCount(SmoothCamPoints.Count); for (int i = 0; i < SmoothCamPoints.Count; i++) { LR.SetPosition(i, SmoothCamPoints[i].pos); } }
// Update is called once per frame void Update() { // use default ray with no dir if there's no HasRay object Ray ray; if (Ray == null) { ray = new Ray(Vector3.zero, Vector3.zero); } else { ray = Ray.GetRay(); } // raycast to get hitInfo if (Physics.Raycast(ray, out _hitInfo, Length, Physics.DefaultRaycastLayers)) { if (OnHoverEvent != null) { OnHoverEvent.Invoke(_hitInfo.collider.gameObject); } } else { if (OnHoverEvent != null) { OnHoverEvent.Invoke(null); } } // draw ray if there's a line renderer and ray is visible if (LR != null) { if (RayVisible) { LR.SetPosition(0, ray.origin); if (HitInfo.collider != null) { LR.SetPosition(1, HitInfo.point); } else { LR.SetPosition(1, ray.origin + ray.direction * Length); } } else { LR.enabled = false; } } }
// Update is called once per frame void Update() { // use default ray with no dir if there's no HasRay object Ray ray; if (Ray == null) { ray = new Ray(Vector3.zero, Vector3.zero); } else { ray = Ray.GetRay(); } // raycast to get hitInfo if (Physics.Raycast(ray, out _hitInfo, Mathf.Infinity, Physics.DefaultRaycastLayers)) { } //Debug.Log(_hitInfo.collider.gameObject.name); // draw ray if there's a line renderer and ray is visible if (LR != null) { if (RayVisible) { LR.SetPosition(0, ray.origin); if (HitInfo.collider != null) { LR.SetPosition(1, HitInfo.point); } else { LR.SetPosition(1, ray.origin + ray.direction * 100f); } } else { LR.enabled = false; } } }
private void SetLRToTarget(RaycastHit hit) { var enemyPosition = hit.point; LR.enabled = true; LR.SetPosition(0, muzzle.position); LR.SetPosition(1, enemyPosition); LR.positionCount = nearestEnemies.Count; if (nearestEnemies.Count > 0) { foreach (var enemy in nearestEnemies) { LR.positionCount++; LR.SetPosition(LR.positionCount - 1, new Vector3(enemy.transform.position.x, enemy.transform.position.y + 3, enemy.transform.position.z)); } } }
private void SetLRToTarget(RaycastHit hit) { LR.enabled = true; LR.SetPosition(0, muzzle.position); LR.SetPosition(1, new Vector3(hit.transform.position.x, hit.transform.position.y + 3, hit.transform.position.z)); }