Quantcast
Channel: Questions in topic: "count"
Viewing all articles
Browse latest Browse all 187

Why is my highScore counting from 10 , not from 0 ??? Thanks in advance :))

$
0
0
using System.Collections; using UnityEngine; public class idemmosc : MonoBehaviour { public float speed = 4f; public Rigidbody2D rb; private float movement = 3f; static int score = 0; static int hiScore = 0; public GUIText text; static public void AddPoint() { score++; if (score > hiScore) { hiScore = score; } } void Start() { score = 0; hiScore = PlayerPrefs.GetInt("hiScore", 0); text.text = "Score" + "\nHiScore" ; } void Update() { movement = Input.GetAxis("Horizontal") * speed; } void FixedUpdate() { rb.MovePosition(rb.position + new Vector2(movement * Time.fixedDeltaTime, 0f)); } void OnCollisionEnter2D(Collision2D other) { PlayerPrefs.SetInt("hiScore", hiScore); if (other.gameObject.name == "Ball") text.text = "Score" + score + "\nHiScore" + hiScore; AddPoint(); } }

Viewing all articles
Browse latest Browse all 187

Trending Articles



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