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
0
Question by DMAD777 · Oct 09, 2015 at 06:18 PM · errorerror message

The left-hand side of an assignment must be a variable, a property or an indexer

Hello i get this error and i dont understand whats i did wrong can you guys help me out?

 using UnityEngine;
 using System.Collections;
 
 public class GoldPerSec : MonoBehaviour {
 
     public UnityEngine.UI.Text gpsDisplay;
     public Click click;
     public ItemManager[] items;
 
     void Awake (){
         if (PlayerPrefs.HasKey ("tick")) {
             GetGoldPerSec() = PlayerPrefs.GetFloat ("tick");
         } else {
             GetGoldPerSec() = 0;
         }
     }
 
     void Start (){
         StartCoroutine (AutoTick ());
     }
 
     void Update (){
         gpsDisplay.text = CurrencyConverter.Instance.GetCurrencyIntoString(GetGoldPerSec(), false, true) + " gold/sec";
         PlayerPrefs.SetFloat ("tick", GetGoldPerSec());
     }
 
     public float GetGoldPerSec (){
         float tick = 0;
         foreach (ItemManager item in items) {
             tick += item.count * item.tickValue;
         }
         return tick;
     }
 
     public void AutoGoldPerSec (){
         click.gold += GetGoldPerSec () / 10;
     }
 
     IEnumerator AutoTick (){
         while(true) {
             AutoGoldPerSec ();
             yield return new WaitForSeconds(0.10f);
     }
 
 }
 }
 

It gives me the The left-hand side of an assignment must be a variable, a property or an indexer Error on line 12 and 14

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by dudester · Oct 09, 2015 at 07:44 PM

first problem is you cant change a functions float value cause a function which in your case is float goldpersec() is not a variable for a variable you want to say like so .

 public float goldpersec;
 

and to set goldpersec you want to use playerprefs.getfloat , but to save it use playerprefs.setfloat . hope this helps.

Comment
Add comment · Show 6 · 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 DMAD777 · Oct 09, 2015 at 09:29 PM 0
Share

It did not work

avatar image dudester · Oct 09, 2015 at 11:14 PM 0
Share

what is it doing?

avatar image DMAD777 dudester · Oct 10, 2015 at 09:20 AM 0
Share

It gives me the same error

avatar image dudester · Oct 10, 2015 at 03:45 PM 0
Share

on a second look at your script you are accessing a script not a function hence the error , unfortunatly i have no idea what you are trying to do so am unable to help

avatar image DMAD777 dudester · Oct 10, 2015 at 03:56 PM 0
Share

Im trying to save the float GetGoldPerSec on line 27 so i can auto save the game using the playerprefs. so if (PlayerPrefs.Has$$anonymous$$ey ("tick")) { GetGoldPerSec() = PlayerPrefs.GetFloat ("tick"); } else { GetGoldPerSec() = 0; } Looks if there is a playerpref called tick and if there isnt one it sets the getgoldpersec to 0 and PlayerPrefs.SetFloat ("tick", GetGoldPerSec()); saves the float every frame

avatar image dudester · Oct 12, 2015 at 02:39 PM 0
Share

ok im going to fix my answer cause on a second look i can see you are confused .

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

33 People are following this question.

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

Related Questions

Multiple .dll files missing, right after installing Unity 0 Answers

Error stage @username 1 Answer

"error CS1525: Unexpected symbol `end-of-file' " I've tried everything.... 1 Answer

My Player Character Have Infinite Jumping + ArgumentException Error 1 Answer

Unity bug gives false error messages or doesen't work without a Debug.Log() line present 1 Answer


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