How can I make scripts work with other scripts

(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;

You need to reference the PlayerScript from the KillScript. So first you just do a variable for it and reference it in the Start function. And when the Player dies decrease the OneUps from the referenced Script by 1.

	public Transform playerSpawn;
	private PlayerMovement playermovement;

	void Start(){
		playermovement = gameObject.GetComponent<PlayerMovement> ();
	}

	void OnTriggerEnter2D (Collider2D other) {
		other.gameObject.transform.position = playerSpawn.position;
		playermovement.OneUps -= 1;
	}
}

Note however, change your

private int OneUps = 5;

to

public int OneUps = 5;

I also assume the Kill and Player Script are on the same gameobject. If they’re not, then you need to change how you reference the Script.

@Metorphium Sorry.
I typed your Script again.
Then i had a Compiler Error.
So i tried Copy and Paste,
but the Compiler Error aren’t gone.
[98713-unbenannt.png|98713]

Just make a reference like so [SerializeField] private PlayerMovement _playerMovement; then attach the movement controller from the editor. For safety you might want to do a null check and then maybe get component if so before using it. Personally I would make the OneUps variable private and then make a get and set method for it.

if you want a single variable that is shared among all scripts it’s as easy as marking them as “Static”.

//put this in your PlayerMovement script.	
public static int test;

//access it anywhere from any script like this:

PlayerMovement.test=5;
print(PlayerMovement.test);