public override void UseEquipment() { if (manager.Movement) { if (!turnedOn) { RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, Mathf.Infinity, ignoreLayers, QueryTriggerInteraction.Collide)) { Vector3 pointInCameraSpace = cam.WorldToViewportPoint(hit.point); /*if (pointInCameraSpace[0] >= 0.0f && pointInCameraSpace[0] <= 1.0f * && pointInCameraSpace[1] >= 0.0f && pointInCameraSpace[1] <= 1.0f * && pointInCameraSpace[2] > 0.0f) {*/ turnedOn = true; manager.Movement.StopMoving(); Vector3 offset = new Vector3(); float offsetAmount = manager.Graph.VertexDistance / 2.0f; switch (manager.Movement.Direction) { case Enums.directions.up: offset.Set(0.0f, 0.0f, -offsetAmount); break; case Enums.directions.down: offset.Set(0.0f, 0.0f, offsetAmount); break; case Enums.directions.left: offset.Set(offsetAmount, 0.0f, 0.0f); break; case Enums.directions.right: offset.Set(-offsetAmount, 0.0f, 0.0f); break; } GameObject temp = Instantiate(targetPrefab, hit.point + offset, Quaternion.identity); temp.transform.forward = manager.transform.forward; target = temp.GetComponent <LaserTarget>(); target.Vertex = manager.Graph.vertices[manager.Graph.GetIndexFromPosition(hit.point + offset)]; target.Pointer = this; LaserUninvestigated(); StartCoroutine("ShootRay", hit.point); //} } } else { turnedOn = false; laser.enabled = false; if (target) { Destroy(target.gameObject); } StopCoroutine("ShootRay"); } } }
/* * Uses Physics.Checksphere to detect any laser pointer in range * if one is found, check whether there is direct line of sight to distraction * if it is in the line of sight, set path to laser */ protected override void CheckForDistraction() { Collider[] hits = Physics.OverlapSphere(transform.position, checkRadius, distractionLayers, QueryTriggerInteraction.Collide); foreach (Collider hit in hits) { if (!Physics.Linecast(transform.position, hit.transform.position, manager.Sight.IgnoreEnemiesLayer, QueryTriggerInteraction.Ignore)) { LaserTarget target = hit.GetComponent <LaserTarget> (); if (target) { GameObject obj = hit.gameObject; SetDistraction(target.Location, ref obj); } } } }