Hi all!
So in my game, I have a player that’s flying around in a what would ideally be a fixed rectangular/square space, but I don’t know how to limit the bounds of my player. Because I’ll be having enemy prefabs coming in from the sides, I wanted to make the fixed area without making an invisible game object to better calculate screen width/height when the game is compiled. Does anyone know how to do this?
I’m also trying to implement a high score + leaderboard in my game, which I’ve never done before. Could anyone direct me to a place where I could figure out how to do this? I want it to work so when the player gets a new high score, they can type in their name and their name would go in the leaderboard.
Here’s my movement/shoot code for now
using UnityEngine;
using System.Collections;
public class PlayerControl : MonoBehaviour {
public float maxSpeed = 0.5f;
bool facingRight = true;
public GameObject playerobject;
private Rigidbody2D squirrel;
public float maxForceSides = 5f;
float playerBoundaryRadius = 0.5f;
//variables for shooting
public Transform firePoint;
public GameObject projectile;
void Start() {
squirrel = GetComponent<Rigidbody2D>();
}
void Update() {
}
void FixedUpdate() {
float move = Input.GetAxisRaw ("Horizontal");
//squirrel.velocity = new Vector2 (move * maxSpeed, squirrel.velocity.y);
float range1x = 1f;
float range1y = 0f;
Vector2 pos = transform.position;
if (Input.GetKey("up") || Input.GetKey(KeyCode.W) || Input.GetKey("down") || Input.GetKey(KeyCode.S)) {
transform.Translate (new Vector3 (0, (Input.GetAxis ("Vertical") * maxSpeed * Time.deltaTime) / 2.5f, 0));
}
if (Input.GetKey("right") || Input.GetKey(KeyCode.D) || Input.GetKey("left") || Input.GetKey(KeyCode.A)) {
transform.Translate (new Vector3 ((Input.GetAxis ("Horizontal") * maxSpeed * Time.deltaTime) / 2.5f, 0, 0));
}
if (move > 0 && !facingRight) {
Flip ();
} else if (move < 0 && facingRight) {
Flip ();
}
//SHOOTING CODE
if (Input.GetKeyDown (KeyCode.Space)) {
Instantiate (projectile, firePoint.position, firePoint.rotation);
}
}
void Flip() {
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
Thanks in advance!