how to save last position for the player before he die

iwant code for save player position before die so when he die start with last position so idont have to restart the level from the beginning thank you.

Add to your player script like this one for example:

using UnityEngine;
using System.Collections;

public class RespawnMe : MonoBehaviour {
	
	private static Vector3 respawnPosition = Vector3.zero;
	private string levelWeAreIn = "";

	void Start () {
		if (levelWeAreIn!=Application.loadedLevelName) {
			levelWeAreIn = Application.loadedLevelName;
			respawnPosition = Vector3.zero;
		}

		if (respawnPosition==Vector3.zero) respawnPosition = transform.position;
		else transform.position = respawnPosition;
	}
	
	void OnDestroy () {
		respawnPosition = transform.position;
	}

}

Create a GameManager script or something along those lines, then create a public static Vector3 and access that variable when you die assigning it the transform.position of the player. Now you just need to access the value of that variable when you restart the level and you should be good to go. Remember to set a default value if you haven’t died before.