Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
KrypTik_Sweller

Help with saving Weapon to player prefs

Question

I am using oma's fps kit and i need some help saving the currently equipped weapons id's to 2 different player pref int's. after that im sure i can figure out how to load them.

accessing it from a different script

would it be something like this?

var Primary : int;

                  WeaponManager WManager = FindObjectOfType<WeaponManager>();
                Primary = WManager.weaponsInUse[0].FindObjectOfType<WeaponIndex>.SetWeapon;
               PlayerPrefs.SetInt("Primary", Primary);

This is just my concept and showing kinda what i hope to accomplish, it is not ment to actually work

Share this post


Link to post
Share on other sites

11 answers to this question

Recommended Posts

  • 1

First of all you should not use playerprefs in update. You can set index when you switch weapons (select weapon).

Please login or register to see this code.

 

Share this post


Link to post
Share on other sites

  • 1

look at this example, it includes attachments but the whole basis of enabling and disabling weapons is included: 

 

 

hope this helps :)

 

Share this post


Link to post
Share on other sites
  • 1

I see your fail you must type getComponent<WeaponIndex>().

 

I think if it is in java the same as in cSharp.

 

Edited by Rhodos32

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

var WManager = weaponManagers.GetComponent("WeaponManager");
                Primary = WManager.weaponsInUse[0].GetComponent("WeaponIndex").SetWeapon;
               PlayerPrefs.SetInt("Primary", Primary);

 

this only comes up with one error now and it is having issues getting the variable weaponsinuse from WManager, any thoughts on why it cant find it?

error:

Assets/_Resources/Scripts/LockCursor.js(60,36): BCE0019: 'weaponsInUse' is not a member of 'UnityEngine.Component'. 

 

weapons in use is a GameObject[] inside of WeaponManager script

Share this post


Link to post
Share on other sites
  • 0

this is the Error I get:

Assets/_Resources/Scripts/Player/WeaponManager.js(58,12): UCE0001: ';' expected. Insert a semicolon at the end.
 

not saying thats what is actually wrong with this line but there.

Please login or register to see this attachment.

Edited by KrypTik_Sweller

Share this post


Link to post
Share on other sites
  • 0

I found it out i had to essentially just seperate everything more, use this

Please login or register to see this link.

 

here is the new code:

private var weaponIndex : WeaponIndex;
private var Primary : int;

 

 

weaponIndex = weaponsInUse[0].GetComponent("WeaponIndex");
    Primary = weaponIndex.setWeapon;
    PlayerPrefs.SetInt("Primary", Primary);

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...