- Home /
error CS0131 Assets/route1.cs(12,25): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer.
really would like some help to make this right. i know its probably something easy I just keep running into a blank wall. first script:
public class route1 : MonoBehaviour {
public bool r1;
void OnMouseDown()
{
if (r1 = true)
{
WR_R1 = true; // line im having troubles with
}
else if (r1 = false)
{
Debug.Log ("wrong play");
}
}
}
Second script:
public class WR_R1 : MonoBehaviour {
void Update(){
iTween.MoveTo(gameObject, iTween.Hash("path", iTweenPath.GetPath("WR_R1"), "time", 9.5));
}
}
Any help or a point into the right direction would be great and very helpful.
Are you trying to check for the existence of a script/class?
http://answers.unity3d.com/questions/44828/test-if-object-has-a-certain-script.html
no i'm trying to set a script active from another if the first one is selected
Arc's method should work. However, when I attempted something similar some time ago I could only enable/disable the gameObject itself; perhaps I was doing it, wrongly.
One thing to note is that when a script is Re-Enabled, the Start method will not run automatically, so if it is essential you will need to manually Invoke Start() to make sure your script is ready to go.
If @Arcadewiz's answer works for you, please mark is as Accepted with the tick.
thank you for the tip but as of now i'm not using the Start method on anything because I don't want anything started when the level is loaded just to run certain animations after it has been selected.
thanks for re$$anonymous$$ding me about that.
GameObject WRObj;
WRObj = GameObject.Find("WR");
// Note 1. This is only if WR is not a child in the hierarchy view
// Note 2. If it is a child then,
// WRObj = GameObject.Find("Parent/(Subparent degree names)*/WR");
WRObj.GetComponent().enabled = true;
This should solve your problems.
Answer by Arcadewiz · Jul 30, 2014 at 08:34 AM
First you have to reference the script WR_R1, by using GetComponent to a referenced gameobject to which it is attached. The gameobject can be referenced by Gameobject.Find.
Then if I understand correctly you need to enable the referenced script on the gameobject if it is disabled.
WR_R1.enabled = true;
Is this what you are trying to do ?
yes that is exactly what i am trying to do thank you ill check it out right now.
so another question how exactly do I use GetComponent and where does it go?? The object that the script is on is called WR.
GetComponent is very versatile. There are thousands of examples on it. Please search.
I have searched a lot and could not fully grasp the idea of how I needed to add it to my script or even where to add it but thanks for all the help.
Answer by Asphyxion · Jul 30, 2014 at 11:06 AM
If I look at your error message you're getting and your first script, all I can see is that you're checking your boolean value in an incorrect way.
Instead of "if (r1 = true)" you should write "if (r1 == true)" or just "if (r1)".
public bool r1;
void OnMouseDown()
{
if (r1 == true)
{
WR_R1 = true; // line im having troubles with
}
else
{
Debug.Log ("wrong play");
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613155349im_/https://answers.unity.com/themes/thub/images/avi.jpg)