- Home /
Value from multiple Gameobjects script
I am trying for hours now to get the value of anothers gameobject script.
I have 10 Levelpictures, each Levelpicture has a script attached what gives the Level number.
A selcetor is detecting the current picture.
in another script i need this value to compare it with somthing.
Sometimes it almost works, but it gives me always a random number.
I tried findeObjectofType, getComponentofType, but nothing seems to work.
The Script is attached to each Levelpicture and has just this in it:
public int thisLevel;
Start(){ thisLevel = gameObject.GetComponent().thisLevel;
to access the value in the other Script ill do(this script is attached to the selcetor):
public LevelINT LV int CurrentLevel;
Start() {
LV = FindObjectOfType();
}
Then ill do in a collision function:
CurrentLevel= LV.thisLevel;
Debug.Log(CurrentLevel);
}
The Console just gives me a random number.
I tried also to use "this" but it didnt work.
i also tried to tag each Level with a name to find it, but still no success.
Can someone help me. I need it to check if the player still needs to finish a level before playing the next.
Thank you
It would be helpful if you put your code in code tags so it is easier to read. As it appears now this is riddled with errors. You aren't passing any types to GetComponent<Type>()
or FindObjectOfType<Type>()
. It appears you have INT LV
as a variable declaration that you're then trying to get thisLevel
from which an int
doesn't contain a definition for. thisLevel = gameObject.GetComponent().thisLevel
doesn't make sense and would only return itself to itself even if the type was declared. If this is the code you are actually running I don't know how your getting anything but errors in the console. It would be best to copy/paste your actual code, make sure all code is spaced at least 4 spaces from the left edge so it all shows up in the code block.
Your answer
Follow this Question
Related Questions
A question about references in C# 2 Answers
How do you access a script if you don't know it's name? 5 Answers
Problems with to many buttons 0 Answers
Object not set to instance of an object 2 Answers