Vector3 point = new Vector3(hitxz.point.x, hity.point.y, hitxz.point.z);
if (teleport_example == null) {
teleport_example = Instantiate(teleport_example_prefab, point, new Quaternion(0, 0, 0, 0));
} else {
teleport_example.transform.position = point;
}
if (Input.GetMouseButtonDown(0)) {
transform.position = point;
Debug.Log("SDFSDF");
}
The weird problem when this code runs is that 'teleport_example.transform.position = point;` works just fine, but when I click the left mouse button, ‘transform.position = point;’ only works every 3 - 30 times. Also, the console shows “SDFSDF” being printed, but the player isn’t being teleported! I tried checking to see if gameObject was null for some odd reason, and it’s not.
Teleport.cs is a component of player, and the code is being run in Update()
Please tell me if you need any more information, and thanks in advance.
I found the solution! It actually was the CharacterController script for some odd reason. The fix was to disable to CharacterController script before I changed transform.position then re-enable it afterwards.
Here is the final portion:
point = new Vector3(hitxz.point.x, hity.point.y, hitxz.point.z);
if (teleport_example == null) {
teleport_example = Instantiate(teleport_example_prefab, point, new Quaternion(0, 0, 0, 0));
} else {
controller.enabled = false;
teleport_example.transform.position = point;
controller.enabled = true;
}
if (Input.GetMouseButtonDown(0)) {
point.y += 1;
transform.position = point;
}
Thank you to @GeroNL for helping me find the solution.