The manual contains this exact line on the topic:
HingeJoint[] hingeJoints = GetComponents<HingeJoint>();
I want to use the same functionality with scripts, so I wrote:
using UnityEngine;
using System.Collections;
public class Switcher : MonoBehaviour {
void SwitchTo(string target) {
Script[] scripts = GetComponents<Script>();
}
}
and Unity replies:
Assets/Scripts/Menus/Switcher.cs(7,17): error CS0246: The type or namespace name `Script’ could not be found. Are you missing a using directive or an assembly reference?
Elsewhere in the manual, ScriptName is used for components in C#, but that gives the same error message.
My best guess is that the part in < > is the literal name of the target script, not its type, which makes absolutely no sense in the context (but seems to work for GetComponent, the singular case). It also has the disadvantage that there’s no way to set the name at runtime (via a variable), because it doesn’t accept a variable in that place.
I’m really confused right now. There seems to be a C# function that can not possibly do what it claims to do. What am I doing wrong?