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 /
avatar image
0
Question by gpuelston2004 · Mar 15, 2019 at 05:20 PM · coinscoingeneral programminggeneral

Is there a better script for permanently deleting items?

So iv been working on a game for awhile now and i'm just getting to making some levels and i have a currency system so i'm making it so the players can collect them threw out the various levels now i have a problem thou as i could just have them respawn in every time i had hoped that they would just delete and be gone so here is the script i used

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using TMPro;
 
 public class PickupMoney : MonoBehaviour
 {
 
     void Start()
     {
         
     }
 
     public static class PlayerData
     {
         private const string playerScoreHash = "score";
         public static int Score
         {
             get
             {
                 return PlayerPrefs.GetInt(playerScoreHash);
             }
             set
             {
                 PlayerPrefs.SetInt(playerScoreHash, value);
             }
         }
     }
 
 
 
 
 
     public static class CoinPickup
     {
         private const string CoinPickupA = "coind";
         public static int coind
         {
             get
             {
                 return PlayerPrefs.GetInt(CoinPickupA);
             }
             set
             {
                 PlayerPrefs.SetInt(CoinPickupA, value);
             }
         }
     }
 
     public GameObject coin;
 
     void Update()
     {
         if (CoinPickup.coind == 1)
         {
             Destroy(coin.gameObject);
         }
     }
 
 
     void OnTriggerEnter(Collider obj)
     {
         if (obj.gameObject.tag == "Player")
         {
             PlayerData.Score += 5;
             CoinPickup.coind = 1;
         }
 
     }
 
 }

But if i used this script i will have to make a new player pref each time is there any way i can make this more efficiently

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 mchts · Mar 20, 2019 at 08:32 PM 0
Share

PlayerPrefs methods are static so you could use it anytime from anywhere i.e. it won't be created it's ready to use.

0 Replies

· Add your reply
  • Sort: 

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

100 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 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 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 avatar image

Related Questions

How can I delete my instantiated prefab coin upon collision? 1 Answer

How do i reload a level but not all objects? 2 Answers

Who can help me with lock/unlock and hint/coin systems? 0 Answers

How to sum up total coins after every level for Game's Home scene. 1 Answer

Particle settings for instant / fast laser? 2 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