how does one pick up a flashlight (object) and turn it on and off

in the project i’m working on trying to get the first person character to have the ability to press a button (for example E) and pick up a flashlight on the ground(that is also a rigid body btw). and to expand on that i alsio wanted to have the ability to turn it on/off via mouse click. if anyone could help me get in the right direction i thank you in advance.

You should add (not replace) a sphere collider to the flashlight and set its Is Trigger field. Add an OnTriggerEnter event to the player script, and a boolean hasFlashlight to tell whether you’ve picked up the flashlight. Create a spotlight and child it to the camera, then adjust its position, rotation, spot angle etc. The player code could be something like this:

private var hasFlashlight = false; // has got a flashlight?
private var flashlight: Light; // reference to the flashlight
private var pickup: GameObject; // reference to the pick up item

function OnTriggerEnter(other: Collider){ // if entered pickup trigger...
  if (other.CompareTag("Flashlight")){ // remember to tag the flashlight!
    pickup = other.gameObject; // save reference to the pickup game object
  }
}

function OnTriggerExit(other: Collider){ // if exited pickup trigger...
  if (other.CompareTag("Flashlight")){
    pickup = null; // null the reference
  }
}

function Start(){
    // find the light attached to the camera...
    flashlight = GetComponentInChildren(Light);
    flashlight.enabled = false; // and make sure it's off
}

function Update(){
  // if inside pickup trigger and E pressed...
  if (pickup && Input.GetKeyDown("e")){
    hasFlashlight = true; // flashlight picked up
    Destroy(pickup); // destroy pick up item
  }
  // if has got flashlight and space is pressed...
  if (hasFlashlight && Input.GetKeyDown("space")){
    // toggle flashlight on/off 
    flashlight.enabled = !flashlight.enabled;
  }
}