In studying scripting I’m trying to work out some issues I’ve been having with accessing components/objects/variables between different scripts.
For testing purposes I created a new project, and created only the following: A Sphere, A GUITexture (left at the default unity watermark), and two scripts.
I’m still very new to scripting, and my syntax is all over the map. While the Unity API has been very helpful, it’s coding examples (when supplied) are rather weak.
This script is attached to the Sphere:
function Update () {
if(Input.GetButtonDown("Fire2")){
GameObject.Find("TestTexture")
.gameObject.enabled=true;
}
}
This script is attached to the GUITexture:
gameObject.enabled=false;
function Update () {
}
This generates two error codes, or rather the same error appearing once for each script:
‘enabled’ is not a member of ‘UnityEngine.GameObject’
Then I rewrote the code as follows:
Sphere
function Update () {
if(Input.GetButtonDown("Fire2")){
GameObject.Find("TestTexture").enabled=true;
}
}
GUITexture:
enabled=false;
function Update () {
}
This provides the same error, but only on the script attached to the Sphere object.
Then as follows:
Sphere:
function Update () {
if(Input.GetButtonDown("Fire2")){
GetComponent(TestTex).enabled=true;
}
}
This provides the error: ‘Object reference not set to an instance of an object.’
Can anyone tell me what the proper syntax for this code would be? Thank you for your time.
[/code]