Search Unity

Question Error using PlayerPrefs and method ToString(

Discussion in 'Scripting' started by rodandres0501, Aug 2, 2020.

  1. rodandres0501

    rodandres0501

    Joined:
    Aug 2, 2020
    Posts:
    8
    Hi, I am trying to use PlayerPrefbs to store an int and value and then show that value on a UI text. But I get 2 errors. The first one is error CS7036: There is no argument given that corresponds to the required formal parameter 'value' of 'PlayerPrefs.SetInt(string, int)' and the second one is error CS0023: Operator '.' cannot be applied to operand of type 'void'.
    Here is the code, I hope you can help me.

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4.  
    5. public class CashManagement : MonoBehaviour
    6. {
    7.     public int InitialCash = 10;
    8.     public int ItemPrice;
    9.     public Text ShowCash;
    10.     void Start()
    11.     {
    12.         PlayerPrefs.SetInt("PlayerCash", InitialCash);
    13.         ShowCash.text=PlayerPrefs.SetInt("PlayerCash");  
    14.     }
    15.    
    16.     public void BuyItem(){
    17.         int ActualCash = PlayerPrefs.GetInt("PlayerCash");
    18.         int NewCash;
    19.         if(ActualCash>=ItemPrice){
    20.             NewCash = ActualCash-ItemPrice;
    21.            PlayerPrefs.SetInt("PlayerCash", NewCash);
    22.             ShowCash.text=PlayerPrefs.SetInt("PlayerCash").ToString();  
    23.         }
    24.     }
    25. }
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
  3. rodandres0501

    rodandres0501

    Joined:
    Aug 2, 2020
    Posts:
    8