Hello I was wondering if in C #, you can change the variables of each script from an array and not by GameObject.Find ("myobject"). GetComponent ()?
In Javascript I do it and it worked!
var tempScripts: Component [];
tempScripts = transform.Find ("Camera") GetComponents (MonoBehaviour);
tempScripts [0] = 1 .blur;
tempScripts [1] .intensity = 10;
tempScripts [2] .CheckPosition ();
--------------------------------------------------
And when I do it in C #
public Component [] tempScript;
tempScript = transform.Find ("Camera") GetComponents ();
tempScript [0] = 1 .blur; // The mistake here.
`UnityEngine.MonoBehaviour 'does not contain a definition for 'blur' and no extension method 'blur' of type UnityEngine.MonoBehaviour 'could be found (are you missing a using directive or an assembly reference?)`
And as I have more than 300 objects and all with their own name and individual script (one different from the other), but they all have the the same variable: ex value.
Another example Java:
var tempScripts: Component [];
var ray: Ray = transform.Find ("Camera") GetComponent (Camera) .ViewportPointToRay (Vector3 (1,1,0));
var hit: RaycastHit;
if (Physics.Raycast (ray hit, 10)) {
tempScripts = hit.collider.gameObject.GetComponents (MonoBehaviour);
tempScripts [0] .value = 10;
}
--------------------------------------------------
And when I do it in C #
Ray ray = transform.Find ("Camera") GetComponent () ViewportPointToRay (new Vector3 (1,1,0));
RaycastHit hit;
if (Physics.Raycast (ray, out hit 10, CameraRaycast)) {
tempScripts = hit.collider.gameObject.GetComponents ();
tempScripts [0] .value = 10; // ERROR HERE
}
`UnityEngine.MonoBehaviour 'does not contain a definition for 'value' and no extension method 'value' of type 'UnityEngine.MonoBehaviour 'could be found (are you missing a using directive or an assembly reference?)
So I was wondering is possible to do in C # which command should I use? Thank you, and sorry for my English.
↧