NullReferenceException: Object reference not set to an instance of an object SwipeTrail.Update () (at Assets/SwipeTrail.cs:50)

Hi I am getting Null reference exception and please find the below mentioned code. I am not able to figure this out

using UnityEngine;
using System.Collections;

public class SwipeTrail : MonoBehaviour
{
public GameObject trailPrefab;
GameObject thisTrail;
Vector3 startPos;
Plane objPlane;

              void Start ()
       		   {
	                 objPlane = new Plane (Camera.main.transform.forward * -1, this.transform.position);

				}
               
                
                void Update () 
                {

	                if ((Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Began) || Input.GetMouseButtonDown (0)) {

			thisTrail = (GameObject)Instantiate (trailPrefab, this.transform.position, Quaternion.identity);

		                            
		                       

		                        Ray mRay = Camera.main.ScreenPointToRay (Input.mousePosition);
		                        float rayDistance;
		                        if (objPlane.Raycast (mRay, out rayDistance))
			                                                    //this.transform.position = mRay.GetPoint (rayDistance);
			                                            startPos = mRay.GetPoint (rayDistance);
	                } else if (((Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Moved) || Input.GetMouseButton (0))) {
		                        
		                        Ray mRay = Camera.main.ScreenPointToRay (Input.mousePosition);
		                        float rayDistance;
		                        if (objPlane.Raycast (mRay, out rayDistance)) 
			                              
								//this.transform.position = mRay.GetPoint (rayDistance);
								thisTrail.transform.position = mRay.GetPoint (rayDistance);
		                               /* Debug.Log ("this trail transform:" + thisTrail.transform);

		                                Debug.Log ("myRay:" + mRay);
		                                Debug.Log ("raydistance:" + rayDistance);*/

		                            
		                          

	                } else if ((Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Ended) || Input.GetMouseButtonUp (0)) {

		                        if (Vector3.Distance (thisTrail.transform.position, startPos) < 0.1)
			                                Destroy (thisTrail);
		                    }

	                        
	                        }
        }

Hey have you solved it out?1

The error occurred on line 50 but it’s hard from the code posted to know what line 50 is since some of the top matter (using, class definition etc) is not in the code section of your post and the line numbers on the left are not at all correct (not your fault - it’s the system…).

I find this type of error most commonly occurs when you create a Public field so that it appears in the Inspector but you don’t drag the relevant object into the Inspector field. You have a public field public public GameObject trailPrefab;. Have you dragged the target prefab from your assets into that field?

If you can post the text of line 50, we can perhaps see more easily where the error occurs.