- Home /
A bunch of errors that I can't fix
I have been looking all over unity answers for this, but have only found questions relating to GUI, which I am not doing. I am getting 6 errors in a script that makes NPCs get out umbrellas if it is raining. Here are the errors:
Assets/Scripts/Umbrella.cs(11,40): error CS0119: Expression denotes a value', where a
method group' was expected
Assets/Scripts/Umbrella.cs(11,25): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer
Assets/Scripts/Umbrella.cs(11,25): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer
Assets/Scripts/Umbrella.cs(14,46): error CS0119: Expression denotes a value', where a
method group' was expected
Assets/Scripts/Umbrella.cs(14,30): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer
Assets/Scripts/Umbrella.cs(14,30): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer
Here is my code:
using UnityEngine;
using System.Collections;
public class Umbrella : MonoBehaviour {
public GameObject Rain;
public GameObject PersonUmbrella;
void Update()
{
if(Rain.SetActive = true())
{PersonUmbrella.SetActive = true;}
else if(Rain.SetActive = false())
{PersonUmbrella.SetActive = false;}
}
}
Answer by YoungDeveloper · Dec 14, 2013 at 06:49 PM
http://docs.unity3d.com/Documentation/ScriptReference/GameObject.SetActive.html
if(Rain.active){ //if is true
PersonUmbrella.SetActive(true);
}
else{ //it is false
PersonUmbrella.SetActive(false);
}
Thanks for the swift reply, the code has no errors, but the umbrella stays inactive. When I try to manually activate it, it deactivates instantly after. What is going wrong, I know that the script is running, and the variables have been assigned correctly.
Yea, you are right, .active is outdated and should not be used. To check activity use this :
http://docs.unity3d.com/Documentation/ScriptReference/GameObject-activeSelf.html
if(Rain.activeSelf){ //if is true
PersonUmbrella.SetActive(true);
}
else{ //it is false
PersonUmbrella.SetActive(false);
}
Ignore me, my mistake. I assigned the rain prefab, not gameobject to the variable. Thanks for helping me!
Your answer
Follow this Question
Related Questions
C# bool setting itself to true 1 Answer
Object activation... 2 Answers
Multiple Cars not working 1 Answer
activating object only on true 1 Answer
True False What am I doing wrong. 1 Answer