- Home /
Question by
mzeman4818 · Aug 28, 2020 at 11:31 PM ·
positiontransform.position
I can't change my players position manually
Once my player dies I want him to go back to his starting location using the code below
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ResetPosition : MonoBehaviour
{
public Vector3 originalPosition;
public Quaternion originalRotation;
public GameObject endCanvas;
public GameObject wall;
void Awake()
{
this.originalPosition = this.transform.position;
this.originalRotation = this.transform.rotation;
}
// call this function to reset this script's object's position and rotation
public void resetTransform()
{
this.transform.position = this.originalPosition;
this.transform.rotation = this.originalRotation;
}
private void Update()
{
if (TimeScript.Instance.time <= 0 || TimeScript.Instance.health <= 0 || endCanvas.activeSelf == true)
{
resetTransform();
wall.SetActive(true);
}
}
}
I changed the update to the code below for testing
private void Update()
{
resetTransform();
print("hello");
}
}
But the player position won't move at all, and I know the code gets activated because of the print
Comment
Have you tried debugging what the original position is?
@Llama_w_2Ls yes, I tried to set it to just 1,1,1 and that didn't work either
Your answer
Follow this Question
Related Questions
can i let the sphere follow a point(x.y. or.z) on plane? 1 Answer
transform.position return the wrong value 0 Answers
Get position relative to another 1 Answer
Help with this script? Keeps moving my objects around in run-time? 0 Answers
A performance question related to setting the position of non-visible objects 1 Answer