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();
}
}
↧