Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
-1
Question by ChaoticDucky · Nov 12, 2016 at 11:24 AM · c#scripting problemerrorcs0131

error cs0131 - The left-hand side of an assignment must be a variable, a property or an indexerplease. help!

please understand that I'm very new to coding and unity but I'm making a endless runner 2d game for ios. i've got a background scroll which won't stop scrolling once the player has died.

so I tried solving that problem with an extra bit of code on the scrolling background script -

 public float speed = 0.5f;
 public GameObject player;

 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
     if (player.SetActive = false) {
         speed = 0.0f;
     }                    

     Vector2 offest = new Vector2 (Time.time * speed, 0);

     GetComponent<Renderer>().material.mainTextureOffset = offest;
 
 }        

}

the error pops up on these lines -

     if (player.SetActive = false) {
         speed = 0.0f;
     }    

Can anyone tell me where I went wrong or how to fix it? Or maybe suggest a different way of stopping the background scroll.

I've searched around the internet so far found nothing of help, other answers only led to me having this specific error.

All I want is for the background to stop scrolling once the player has died :(

any help is much appreciated.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TreyH · Nov 12, 2016 at 12:27 PM 1
Share

GameObject.SetActive() is a function. :-)

There's a default property that lets you check whether something is active in your scene, so your check would become:

 if ( player.activeInHierarchy == false )
 {
     speed = 0.0f;
 } 

Also (since you are admittedly new to coding), note the use of ==. When comparing whether or not a value equals another value, you will need to use the == notation. A single = is only used when assigning a value.

avatar image ChaoticDucky TreyH · Nov 12, 2016 at 01:01 PM 0
Share

thanks so much!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by roman_sedition · Nov 12, 2016 at 12:50 PM

You could try this out, make a bool which, dictates if the player is dead or alive.

 public bool dead;
 
 
 void Start(){
      dead = false;
 }

Then when the player dies, assign the bool to true.

 dead = true;

 

In your update you make a check to see if dead is true.

 void Update () {
      if (dead == true) {
          speed = 0.0f;
      }                    


I feel if you are new to this you should probably use bools, it will help you understand how conditional statements work better and makes it easier to step through your code when you debug, and yes as mentioned you should use == if you want to check a condition if something equals a condition. If you are setting your gameobjects as inactive when you are new to this, you might create more problems for yourself.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ChaoticDucky · Nov 12, 2016 at 01:00 PM 0
Share

Thanks for the help and suggestions! I'll keep a lot of this in $$anonymous$$d.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

C# - Cannnot access variable in another script unless I get the component everytime. 1 Answer

Menu object not responding 0 Answers

I can't figure this out. I have Unity 5.3.1 and this error keeps popping up. error CS0029 1 Answer

"The associated script cannot be loaded." 0 Answers

Error CS0120 : An object reference is required to access non-static member 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges