Quantcast
Channel: Questions in topic: "saves"
Viewing all articles
Browse latest Browse all 14

Problems implementing Highscore Saves

$
0
0
Hello peeps :) I am currently developing a game for mobile devices which is heavily score based. We have a scoring system on the level itself but we are trying to add a simple system where the game will save your highest score onto the main menu however we seem to be having a problem with this. We understand this question has been asked a lot and we have tried using a couple of peoples solutions but we have had no success as of yet. We understand we need to use PlayerPrefs and have tried to implement it into our code, but the problem is that it saves the score, even if it is less than the old high score. using UnityEngine; using System.Collections; public class EnemyMove : MonoBehaviour { float speed = 3.0f; // move speed public static int score = 0; public GameObject Explosion; int oldHighscore; void Update(){ if (GameObject.FindGameObjectsWithTag ("Player") != null && PointAndFire.Hit >= 1) { GameObject target = GameObject.FindGameObjectWithTag ("Player"); transform.position = Vector3.MoveTowards (transform.position, target.transform.position, speed * Time.deltaTime); } else if (GameObject.FindGameObjectsWithTag ("Player") == null) { } if (score > oldHighscore) { PlayerPrefs.SetInt ("highscore", score); oldHighscore = score; } } void OnCollisionEnter (Collision col) { if(col.gameObject.name == "bullet 2(Clone)") { Destroy(col.gameObject); score += 1; Debug.Log(score); Instantiate (Explosion,transform.position, transform.rotation); } } void OnCollisionPlayer (Collision col) { if(col.gameObject.tag == "Player") { Destroy(gameObject); } } } Any help would be greatly appreciated, Thanks!

Viewing all articles
Browse latest Browse all 14

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>