How do I make a general script that uses an unknown object?

I’m not completely sure if this is possible, but I’m making a puzzle game, and want a general script that I can assign an object to a public variable, then put that script on some toggled object, like a door that will be opened when a lever is pressed.
ex: Put the script on a door, attach a lever to the script in the object, then put the same script on a different door, and attach a different lever to the script in that object.
Will that work, or is there a different method that will have the same result?

@Sir_Aulen

This is a script that can contain as many doors and switches as you want. Each element of the list can hold one door and multiple switches. So hopefully it works for you all having troubles. Cheers:

Script:

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

public class DoorActivator : MonoBehaviour {
    //Call the class holding the door and switches
    public List<ActivateDoor> activators;

	// Use this for initialization
	void Start () {
        //Setting up our status holders
        for (int i = 0; i < activators.Count; i++)
        {
            activators*.activatedSwitches = new Dictionary<string, bool>();*

}
}

  • // Update is called once per frame*
  • void Update () {*
    //Loop through the activators
    for (int i = 0; i < activators.Count; i++)
    {
    //If our switches are all activated
    if (activators_.activatedSwitches.Count == activators*.switches.Count)
    //Loop through the activated switches in the current activator element*
    for (int j = 0; j < activators*.activatedSwitches.Count; j++)*
    {
    //Then loop through all the switches
    for (int k = 0; k < activators*.switches.Count; k++)*
    {
    //We double check to see if our switches are true
    if (activators.activatedSwitches[activators*.switches[k].name] == true)
    {
    //And if they are then activate our door._

    _activators.door.SetActive(true);
    }
    }
    }
    }
    }*_

private void OnTriggerEnter(Collider other)
{
//Go through each activator created in the editor
for (int i = 0; i < activators.Count; i++)
{
//Go through each switch in each element of the activators
for (int j = 0; j < activators*.switches.Count; j++)*
{
//If the other object that we interacted with is one of our switches
//and our list does not already have it then set it
//as activated. Meaning add it to the activatedSwitches list.
if (other.gameObject == activators*.switches[j]*
&& !(activators_.activatedSwitches.ContainsKey(activators*.switches[j].name)))
{
//We add the activated switch to the activator containing it and set it to true.
activators.activatedSwitches.Add(activators.switches[j].name, true);
}
}
}
}
}*_

[System.Serializable]
public class ActivateDoor
{
//The de-activated door object
[Header(“Make sure the doors are de-activated”)]
public GameObject door;

//The switches or switch to activate the door
[Header(“Add Switches To This”)]
public List switches;

//Statuses of the switches (On/Off)
[Header(“These will show you which switches have been activated.”)]
public Dictionary<string, bool> activatedSwitches;
}
2D Version On @Sir_Aulen Request:
Script2D:
@Sir_Aulen

using System.Collections.Generic;
using UnityEngine;

public class New : MonoBehaviour {
//Call class of door and switches
public List activators;
public int locked;

* void Start () {*
//Set up status holders
for (int i = 0; i < activators.Count; i++)
{
activators*.activatedSwitches = new Dictionary<string, bool>();*
}
}

* void Update () {*
//Loop through the activators
for (int i = 0; i < activators.Count; i++)
{
//If our switches are all activated
if (activators_.activatedSwitches.Count == activators*.switches.Count)
//Loop through the activated switches in the current activator element*

for (int j = 0; j < activators*.activatedSwitches.Count; j++)*
{
//Then loop through all the switches
for (int k = 0; k < activators*.switches.Count; k++)*
{
//We double check to see if our switches are true
if (activators.activatedSwitches[activators*.switches[k].name] == true)
{
//And if they are then activate our door.
//Instead of having this here you can switch it to do something else for your*

//door
if (locked > 1)
{
activators*.door.GetComponent().SetInteger(“Toggled”, 1);*
}
//activators*.door.SetActive(true);
//Turn off that collider*

activators*.door.GetComponent().enabled = false;*
}
}
}
}
* }*_

private void OnTriggerEnter2D(Collider2D other)
{
//Go through each activator created in the editor
for (int i = 0; i < activators.Count; i++)
{
//Go through each switch in each element of the activators
for (int j = 0; j < activators*.switches.Count; j++)*
{
//If the other object that we interacted with is one of our switches
//and our list does not already have it then set it
//as activated. Meaning add it to the activatedSwitches list.
if (other.gameObject == activators*.switches[j]*
&& !(activators_.activatedSwitches.ContainsKey(activators*.switches[j].name)))
{
//We add the activated switch to the activator containing it and set it to true.
activators.activatedSwitches.Add(activators.switches[j].name, true);
}
}
}
}*_

private void OnTriggerExit2D(Collider2D other)
{
//Go through each activator created in the editor
for (int i = 0; i < activators.Count; i++)
{
//Go through each switch in each element of the activators
for (int j = 0; j < activators*.switches.Count; j++)*
{
//If the other object that we interacted with is one of our switches
//and our list does not already have it then set it
//as activated. Meaning add it to the activatedSwitches list.
if (other.gameObject == activators*.switches[j]*
&& !(activators_.activatedSwitches.ContainsKey(activators*.switches[j].name)))
{
//We add the activated switch to the activator containing it and set it to true.
activators.activatedSwitches.Add(activators.switches[j].name, false);*_

if (locked > 1)
{
activators*.door.GetComponent().SetInteger(“Toggled”, 0);*
activators*.door.GetComponent().enabled = true;*
}

}
}
}
}
}

[System.Serializable]
public class ActivateDoor
{
//You can add any gameObject including 2d ones
[Header(“Make sure the doors are de-activated”)]
public GameObject door;
//This can hold any amount of gameObjects even 2D ones
[Header(“Add Switches To This”)]
public List switches;

//Statuses of the switches (On/Off)
[Header(“These will show you which switches have been activated.”)]
public Dictionary<string, bool> activatedSwitches;
}