Hi all,
How can I access a script of an object without knowing the name of the script?
Sorry for my english
Thank you in advance
Hi all,
How can I access a script of an object without knowing the name of the script?
Sorry for my english
Thank you in advance
you can not access something unknown.
What you though can do is use SendMessage to just call a function with a data object on a specific game object.
every component having a function that fullfills the requirements will call that function then.
I only need to activate the script.
I have a script attach to the camera tha raycast objects in a “raycast visible layer”
// Raycast up to 3 meters forward
var cursorGuiText : GameObject;
function Update () {
var layerMask = 1 << 8;
var hit : RaycastHit;
if (Physics.Raycast (transform.position,
transform.TransformDirection (Vector3.forward),
hit, 3.0, layerMask)) {
distanceToGround = hit.distance;
cursorGuiText.guiText.enabled = true;
// If mouseclick enable the script in the hit object;
if (Input.GetButton ("Fire1")) {
print ("Hai cliccato");
}
}
else
cursorGuiText.guiText.enabled = false;
}
Each object in the layer has a gui script attach to it but they are different from object to object.
function OnGUI () {
if (GUI.Button (Rect (10,10,150,100), "I am a button")) {
print ("You clicked the button!");
}
}
How can Activate only the script attach to the hit object? Can you make me some exapmple?