ставлю координаты 1.563 по x но когда включаю игру телепортирует на 0 по x
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private CharacterController controller;
private Vector3 dir;
[SerializeField] private int speed;
private int linetomove = 1;
public float LineDistance;
// Start is called before the first frame update
void Start()
{
controller = GetComponent<CharacterController>();
}
private void Update()
{
if (SwipeController.swipeRight)
{
if (linetomove < 2)
linetomove++;
}
if (SwipeController.swipeLeft)
{
if (linetomove > 0)
linetomove--;
}
Vector3 targetPosition = transform.position.z * transform.forward + transform.position.y * transform.up;
if (linetomove == 0)
targetPosition += Vector3.left * LineDistance;
else if (linetomove == 2)
targetPosition += Vector3.right * LineDistance;
Vector3 diff = targetPosition - transform.position;
Vector3 moveDir = diff.normalized * 25 * Time.deltaTime;
if (moveDir.sqrMagnitude < diff.sqrMagnitude)
controller.Move(moveDir);
else
controller.Move(diff);
}
// Update is called once per frame
void FixedUpdate()
{
dir.z = speed;
controller.Move(dir * Time.fixedDeltaTime);
}
}