(with messages between the scripts or something)
The player script and the kill script have to interact with each other so that the kill script divides the 1-ups variable from the player script by 1 when the player dies.
Kill Script:
public Transform playerSpawn;
void OnTriggerEnter2D (Collider2D other) {
other.gameObject.transform.position = playerSpawn.position;
}
}
Player Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
// --> Player Movement <-- //
public float moveSpeed;
public float jumpHeight;
public Transform groundCheck;
public float groundCheckRadius;
public LayerMask whatIsGround;
private bool grounded;
private bool doubleJumped;
void Start ()
{
}
void FixedUpdate () {
grounded = Physics2D.OverlapCircle (groundCheck.position, groundCheckRadius, whatIsGround);
}
void Update ()
{
if (grounded)
{
doubleJumped = false;
}
if (Input.GetKey (KeyCode.Space) && grounded)
{
GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jumpHeight);
}
if (Input.GetKeyDown (KeyCode.Space) && !doubleJumped && !grounded)
{
GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jumpHeight);
doubleJumped = true;
}
if (Input.GetKey (KeyCode.RightArrow))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
}
if (Input.GetKey (KeyCode.LeftArrow))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(-moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
}
}
}
// --> 1ups System <-- //
private int OneUps = 5;