- Home /
How can I access a variable from another script in a separate object?
This is in javascript. Please do not give an answer in C#.
I am having trouble with this code to get an achievement. I have tried quite a lot and looked at other questions and nothing works. it give me the following errors with the following scripts.
Errors for script "displayAchievement":
Unknown Identifier: 'texName'.
Unknown Identifier: 'give'.
Script "display achievement": (attached to "Achievement" gameobject)
#pragma strict
function Start () {
}
function Update () {
}
function Awake ()
{
var reciever_obj = GameObject.Find("achivementReciever");
var script = reciever_obj.GetComponent(detectAchievement);
var texNameRecieved = script.GetComponent(texName);
var getAchivement = script.GetComponent(give);
if ( getAchivement == true )
{
GameObject.Find("Achievement").guiTexture.texture = texNameRecieved;
guiTexture.enabled = true;
}
}
My other script has no errors. Script name: detectAchievement
Attached to: achievementReciever
Script:
#pragma strict
function Start () {
}
function Update () {
}
var texName : Texture;
var give : boolean = false;
I don't get why it errors. PLEASE HELP!
Answer by robertbu · Mar 23, 2013 at 04:25 PM
You are close. Once you have access to the script, you don't need GetComponent(). Try:
var texNameRecieved = script.texName;
var getAchivement = script.give;
Your answer
Follow this Question
Related Questions
How do I change the text of a GUIText object through another GameObject using a variable? 2 Answers
how can I display a variable as a GUIText 5 Answers
How to access gameObject variable script 2 Answers
How do I track an object of a specific type at collision? 0 Answers
[Solved]Instantiating prefab from a script and destroy it from another one 2 Answers