Unity 2d Reset Player position
Code Example - Unity 2d Reset Player position
public class player : MonoBehaviour
{
//Declare Variables
Rigidbody2D rb2d;
Vector2 p_startPosition;
void Start()
{
//Stores the rigidbody component in a variable
rb2d = GetComponent<Rigidbody2D>();
//Stores the RigidBody start position
p_startPosition = gameObject.transform.position;
}
void FixedUpdate()
{
if (Input.GetKey(KeyCode.R))
{
//Resets the player the start position
rb2d.transform.position = p_startPosition;
//Resets the player the start Rotation
rb2d.transform.rotation = Quaternion.identity;
}
}