I'm getting a NullReferenceException for Camera.main

I’m currently making a game and i was going to implement dashing in the game when i encountered a tiny problem. In the rb.AddForce(Camera.main.transform.forward * dashForce, ForceMode.Force); statement there was an error and i could fix it by removing Camera.main. Why is this happening, Below is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Dash : MonoBehaviour
  [SerializeField] private float dashForce; // should be 30000 or 35000 or somewhere in between or roughly around these numbers
  [SerializeField] private float dashDuration;
  public float dashCoolDownTime = 3;
  public KeyCode dashKey;
  private float nextDashTime;

  private Rigidbody rb;

  private void Awake()
    rb = GetComponent<Rigidbody>();

  private void Update()
    if (Time.time > nextDashTime)
      if (Input.GetKeyDown(dashKey))

  public IEnumerator Do_Dash()
    rb.AddForce(Camera.main.transform.forward * dashForce, ForceMode.Force);

    yield return new WaitForSeconds(dashDuration);

    rb.velocity = Vector3.zero;
    nextDashTime = Time.time + dashCoolDownTime;

Btw, i am using the dash Tutorial from DapperDino (Creating Genji - Dash & Double Jump - Part 1 - Unity Tutorial - YouTube).

When in question why something like Camera.main doesn’t work, the first thing you should consult is the manual. You get that by just typing “Unity Camera.main” into google . Here it is. What does it say?


The first enabled Camera component
that is tagged “MainCamera” (Read

If there is no enabled Camera
component with the “MainCamera” tag,
this property is null.

Given the description of what this property does, what may be your issue? Right, there is no enabled camera in the scene that is tagged “MainCamera”