// Update is called once per frame void Update() { // If the first mouse button(LMB) is tapped down: if (Input.GetMouseButtonDown(0)) { // Getting the mid point of the screen whats basically the width/2 and height/2. Vector3 point = new Vector3(_camera.pixelWidth / 2, _camera.pixelHeight / 2, 0); // Method of Unity Script to configure raycasting. Ray ray = _camera.ScreenPointToRay(point); // Datatype what deals with intersections of the ray. RaycastHit hit; /* * 'out' ensures that the data structure manipulated within the command is the same * object that exists outside the command. */ if (Physics.Raycast(ray, out hit)) { // Checking if the ray hits at which point. // Debug.Log("Hit: " + hit.point); // Coroutines does a job after with pauses indicated by the developer. // Create an object and deletes it afterwards. // The object that was hit. GameObject hitGameObject = hit.transform.gameObject; // For checking if the target has ReactiveTarget component. ReactiveTarget target = hitGameObject.GetComponent <ReactiveTarget>(); if (target != null) { // Debug.Log("Hit! " + ++_counter_of_hit); target.react_to_hit(); } else { StartCoroutine(HitIndicator(hit.point)); } } } }