So I wrote a script:
void Respawn () {
transform.position = new Vector 3 (-17.52, 3.95, 9.12);
}
void Update () {
if (Input.GetButtonDown(KeyCode.R)) {
Respawn ();
}
}
Why is it not working when I press ‘r’?
So I wrote a script:
void Respawn () {
transform.position = new Vector 3 (-17.52, 3.95, 9.12);
}
void Update () {
if (Input.GetButtonDown(KeyCode.R)) {
Respawn ();
}
}
Why is it not working when I press ‘r’?
If you look at the documentation for Input.GetButtonDown you’ll see that it expects a string representing a virtual button defined in the input manager. In theory your code wouldn’t even compile since KeyCode.R isn’t a string.
What you want instead is to use Input.GetKeyDown which looks for a key press.
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
Respawn();
{
}