Laser System - "If" statement conflict

Okay, it is the complicated question, but I will try to explain the problem.
So, I’m making 2d laser system, where is to rays from two sides are detecting the player who tries to collide with the laser.

123511-screen-shot-2018-08-11-at-224557.png

The main problem here I think thank two “if” are conflicting, so Only One side are working and detecting the player, which is giving him damage, the not working side is just know that ray detect the player.
I hope the code will not look like something hard to understand.

Here is it:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OneLaserScript : MonoBehaviour {

	private LineRenderer lineRenderer;

	public Transform laserHit;

	public GameObject player;

	public Transform leftCheck, rightCheck;

	public Transform leftHit, rightHit;

	public bool spottedLeft, spottedRight;

	public LayerMask detectionLayers;

	public LayerMask playerDetection;

	void Start () 
	{
		lineRenderer = GetComponent<LineRenderer> ();
	}
	void FixedUpdate () 
	{
		float distan = Mathf.Infinity;
		RaycastHit2D hit = Physics2D.Raycast (transform.position, transform.up,distan,playerDetection); //Direction of the laser

		if (hit.transform != null)
		{
			lineRenderer.enabled = true;
			laserHit.position = hit.point;
			lineRenderer.SetPosition(0, transform.position);
			lineRenderer.SetPosition(1, laserHit.position);
		}
		else
		{
			lineRenderer.enabled = false;
		}

		if (hit.collider != null) {

			laserHit.position = hit.point;
			lineRenderer.SetPosition (0, transform.position);
			lineRenderer.SetPosition (1, laserHit.position);

			Debug.DrawLine (leftCheck.position, leftHit.position, Color.green);
			spottedLeft = Physics2D.Linecast (leftCheck.position, leftHit.position, detectionLayers);

			Debug.DrawLine (rightCheck.position, rightHit.position, Color.green);
			spottedRight = Physics2D.Linecast (rightCheck.position, rightHit.position, detectionLayers);

			if (spottedRight == true && spottedLeft == false) {
				player.GetComponent<Rigidbody2D> ().AddForce(new Vector2 (-5000, 1000));
				player.GetComponent<PlayerControllerScript> ().laserHit = true;
				player.GetComponent<PlayerControllerScript> ().knockFromRight = true;
			} else {
				player.GetComponent<PlayerControllerScript> ().laserHit = false;
			}
			if (spottedLeft == true && spottedRight == false) {
				player.GetComponent<PlayerControllerScript> ().laserHit = true;
				player.GetComponent<PlayerControllerScript> ().knockFromRight = false;
			} else {
				player.GetComponent<PlayerControllerScript> ().laserHit = false;
			}
		}
	}
}

There is some context missing here.

I don’t see, for example, where leftCheck and rightCheck are assigned values, and I don’t know if this script is only on one GameObject or two GameObjects.

However, if I guess that this script applies to one and only one game object, but your text suggests there are two laser beams used for sensing collision, you are only testing one.

I get a hint from the debug.drawlines that there is only one such script. While those debug lines appear to draw two positions, I see only one raycast being tested, so I’d expect only one thing is going to collide.

If your text reference to “two if” are conflicting corresponds to lines 32 and 44 of this post, that’s not exactly a problem, but it is a bit odd. I’m not sure what circumstance provides a collider but no transform, but I don’t see how these two forms causes a problem, they are largely redundant except for the lineRenderer.enabled setting.

If you do have two GameObjects, and this code is attached to both, perhaps I’m incorrect here, but at the moment it seems you need two raycasts, one for each side you’re detecting.