- Home /
[C#] Assets/BreakObject.cs(20,62): error CS0165: Use of unassigned local variable `broken'
Hello, today I ran into a problem while messing around with some concepts and I can't seem to work out how to fix it. On one of my scripts unity straight up refuses to recognize a public variable as such, I've tried restarting several times and every time I get the same error. Here is a bit of the script in question.
public class BreakObject : MonoBehaviour {
public GameObject broken;
void Update () {
As that clearly shows 'broken' is a public variable yet no matter what I try unity refuses to recognize that it is and insists on treating it as a local variable.
Anyone had this problem or know how to fix it? It's really annoying that I can't go on with my project.
Thanks for your help!
Answer by robertbu · Jul 23, 2014 at 06:45 PM
You don't show us enough of the code to figure out the issue. Any chance you are declaring this variable again inside a function? For example if you did this:
public class BreakObject : MonoBehaviour {
public GameObject broken;
void Update () {
GameObject broken;
broken.transform.positon = Vector3.zero;
}
}
...your code would generate the error.
Your answer
Follow this Question
Related Questions
Getting a variable from another script 2 Answers
Multiple Cars not working 1 Answer
Accessing variable from a method in another script and gameObject 2 Answers
how do i get a public variable from another script 1 Answer
Distribute terrain in zones 3 Answers