- Home /
Cannot Locate Boolean in different script
Alright here is the problem, I am trying to get the moved boolean in one script so I can use it in another script. I've declared it public var moved : boolean = false;
and it even shows up with the little check box in the inspector. But then I try to access it from a script attached to a different game object, like this:
Physics.Raycast(transform.position, Vector3.right, hit, 3.0);
if(hit.collider.gameObject.tag.Contains("tile")){
var tile = GameObject.FindGameObjectWithTag(hit.collider.gameObject.tag);
Debug.Log(tile.moved);
I get "Assets/Script/Shuffle.js(29,48): BCE0019: 'moved' is not a member of 'UnityEngine.GameObject'."
and I've tried Debug.Log(tile.GetComponent("Slider").moved);
Slider.js being the name of the first script.
So anyone know why it cant be found?
Answer by easilyBaffled · Jul 09, 2012 at 07:19 PM
Thank you everyone for you suggestions. Unfortunately, as it usually is, the problem was just a stupid mistake. I had tile.GetComponent("Slider").moved
when the quotes were unnecessary its just tile.GetComponent(Slider).moved
Answer by Screwworkn · Jul 09, 2012 at 07:03 PM
You are at the gameobject and you need to reference the script component that is on the game object. Here is the idea in C#.
//Get GameObject
GameObject newBall = (GameObject)Instantiate (Ball);
//Get ScriptObject from the GameObject
BallScript bs = (BallScript)newBall.GetComponent (typeof(BallScript));
//You can now access properties.
bs.BallSpeed = 10;
Answer by Ingen · Jul 09, 2012 at 07:03 PM
missing "" for error-"Assets/Script/Shuffle.js(29,48)...'moved' is not a member... Debug.Log("tile.moved");
take a look at this to take a function in another script
it work, just have another problem about the animation
Answer by Eric5h5 · Jul 09, 2012 at 06:42 PM
You need to use GetComponent with the GameObject that's returned by FindGameObjectWithTag. The variable is part of the script component, not the GameObject.
That's what I am doing, I assigned the result of FindGameObjectWithTag to tile, then tried to get it from tile. Just to make sure I tried (GameObject.FindGameObjectWithTag(hit.collider.gameObject.tag).GetComponent("Slider").moved); And it still won't find it. Or am I just missing something completely?
Your answer
![](https://koobas.hobune.stream/wayback/20220613073929im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Disable / enable script 2 Answers
Turning a menu on and off onclick in hololens 0 Answers
Bool based on objects existing not changing. 2 Answers
Boolean Not Changing 1 Answer