Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
2
Question by Holyheadit · Nov 30, 2012 at 09:59 PM · playerprefsnullsetting

player pref first time set up

hi im trying to set the player pref for first time a player uses the game. so i want to do

 if(PlayerPrefs.GetInt("example") == null)
 {
 PlayerPrefs.SetInt("example",1)
 }

is null the default setting on playerprefs? thanks

Comment
Add comment · Show 1
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 LijuDeveloper · Jun 30, 2014 at 12:12 PM 0
Share
  string isLoginOnce  = PlayerPrefs.GetString ("_isLoginOnce");

  if(isLoginOnce !="True")
  {
 PlayerPrefs.SetString ("_isLoginOnce","True");
 PlayerPrefs.SetString("playerName",userName);
 PlayerPrefs.SetString("playerPassword",userPassword);
  }

  if(isLoginOnce == "True")
  {
         
 print (" isLoginOnce "+isLoginOnce);
 userName = PlayerPrefs.GetString("playerName");
 userPassword = PlayerPrefs.GetString("playerPassword");
  }

2 Replies

· Add your reply
  • Sort: 
avatar image
18

Answer by Mehul-Rughani · Jun 30, 2014 at 12:40 PM

PlayerPrefs.HasKey("example")

it will return true if it is assigned already otherwise it will return false..

so You Can Write

if(!PlayerPrefs.HasKey("example")) PlayerPrefs.SetInt("example",1);

Comment
Add comment · Show 3 · 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 HoangYell · Nov 08, 2015 at 04:29 AM 0
Share

thanks, you saved my life :))))))

avatar image joonhoriderlee · Jul 26, 2020 at 03:41 PM 0
Share

you saved me so much time thank you!

avatar image Chethan007 · Jun 13, 2021 at 05:08 PM 0
Share

Absolutely correct. You saved my day man!!

avatar image
11

Answer by DaveA · Nov 30, 2012 at 10:00 PM

Just use

PlayerPrefs.GetInt("example", 1);

Comment
Add comment · Show 3 · 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 Holyheadit · Nov 30, 2012 at 10:13 PM 0
Share

getintexample? i found the default is 0 so i put .setint(example,1) thanks

avatar image Eric5h5 · Nov 30, 2012 at 10:22 PM 3
Share

@Holyheadit: The point is that GetInt allows you to set a default value. So you never need to check for whether anything is null. e.g.,

 var foo = PlayerPrefs.GetInt("foo", 99);

This way foo is set to 99 if there is no player prefs set for "foo", otherwise it gets the value from what was saved. Then later you just do

 PlayerPrefs.SetInt("foo", foo);

later on as usual. You don't need to use SetInt to set a default value, since that's already taken care of with GetInt.

avatar image Holyheadit · Dec 04, 2012 at 04:46 PM 0
Share

i meamt on a first time run im looking for first time settings so if it wasby default 0 then if(getint=0) go settings

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

19 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

how to save a load a game? 1 Answer

XMLDocument GetElementByID returning null 1 Answer

How to change the color of the screen?? 3 Answers

Nullreferencexception using PlayerPrefs.GetInt and GetString 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