a problem with a public static bool in very very simple 2d game

hello guys, sorry for my english(i live somewhere in post ussr ), i am almost total n00b in programming and i wanted to create my very first game just to share it with my friends.
This is a pretty simple 2d android game where bombs are falling at the player and player needs to move in x axis to avoid them( i am doing it by a guide).
So, the problem is that i was doing actions in case of losing, and i have already done script file which determines the losing itself

public class player : MonoBehaviour {


	public static bool lose = false;

	void OnTriggerEnter2D (Collider2D other) {
		if (other.gameObject.tag == "enemy")
			lose = true;
	}

}

then i inserted the “while (!player.lose)” before the bombs spawning script so the bombs stop spawning after you lose and it worked fine

using System.Collections;
using UnityEngine;

public class SpawnEnemies : MonoBehaviour {

	public GameObject enemy;

	void Start () {
		StartCoroutine (Spawn ());
		
	}
	
	IEnumerator Spawn () {
		while (!player.lose) {
			Instantiate (enemy, new Vector2 (Random.Range (-2.4f, 2.4f), 5.79f ), Quaternion.identity ); 
			yield return new WaitForSeconds (1.5f);
	}
	}
}

and then i tried to do the same action with moveplayer script because i wanted that you won’t be able to move player anymore after losing but it failed with error “Assets/scripts/moveplayer.cs(12,14): error CS1061: Type UnityEngine Transform does not contain a definition for lose and no extension method lose of type UnityEngine Transform could be found. Are you missing an assembly reference?”|
the script moveplayer itself looked like this:

using UnityEngine;

public class moveplayer : MonoBehaviour {

	public Transform player;
	[SerializeField]
	private float speed = 10f;

	void OnMouseDrag () {

		if(!player.lose) {
		
		
		Vector3 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
		mousePos.x = mousePos.x > 2.4f ? 2.4f : mousePos.x;
		mousePos.x = mousePos.x < -2.4f ? -2.4f : mousePos.x;
		player.position = Vector2.MoveTowards (player.position, 
			new Vector2 (mousePos.x, player.position.y),
			speed * Time.deltaTime);
		}
	}
}

sorry if it’s stupid problem but as i said i am total newbie and i did’nt find answers on the internet…
so how i can make it work fine? thanks!

oh, actually when you carefully describe your problem it makes you think better. So the trouble was about lowercase & uppercase letters, because in moveplayer script i already had a define for player.

I men, this code don’t work because you search lose in player but player is a Transform variable not your script of class ‘player’ so you need to call this script :

if (!player.GetComponent<Player>().lose)

or use a variable of class Player which assign your script directly

public Player player;

also set the first letter of your class name with a capital letter to not confuse them with a variable name like i do just above ‘player’ ‘Player’

So your three script corrected :

using UnityEngine;
public class Player : MonoBehaviour {
	public bool lose = false; 
	void OnTriggerEnter2D (Collider2D other)
	{
		if (other.gameObject.tag == "enemy")
		lose = true;
	}
}
using UnityEngine;
using System.Collections; 
public class SpawnEnemies : MonoBehaviour { 
	public GameObject enemy;
	public Player player;
	void Start ()
	{
		StartCoroutine (Spawn ());
	}
	IEnumerator Spawn ()
	{
		while (!player.lose)
		{
			Instantiate (enemy, new Vector2 (Random.Range (-2.4f, 2.4f), 5.79f ), Quaternion.identity); 
			yield return new WaitForSeconds (1.5f);
		}
	}
}
using UnityEngine;
public class Moveplayer : MonoBehaviour {
	[SerializeField]
	private float speed = 10f;
	public Transform player;
	void OnMouseDrag ()
	{
		if (!player.GetComponent<Player>().lose)
		{
			Vector3 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
			mousePos.x = mousePos.x > 2.4f ? 2.4f : mousePos.x;
			mousePos.x = mousePos.x < -2.4f ? -2.4f : mousePos.x;
			player.position = Vector2.MoveTowards (player.position, 
			new Vector2 (mousePos.x, player.position.y),
			speed * Time.deltaTime);
		}
	}
}

I don’t use a static variable in class Player you don’t need it, it’s cleaner like this.

I hope I help, Sean.