У меня есть персонаж, на котором, если я нажимаю A или D, он переходит влево или вправо, но проблема в том, что он не переходит в одну и ту же позицию последовательно.
Если я нажму D, он переместится вправо в какую-то позицию, затем перезапустит сцену и снова нажмет D, она перейдет вправо, но окажется в другой позиции, даже если я дал значения x и yк этому.
Вот мой код ниже:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float jumpSpeed;
public int jumpHeight;
public float Xincrement;
public float Zdecrement;
void Awake()
{
rb = GetComponent<Rigidbody>();
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.D))
{
GetComponent<Rigidbody>().velocity = new Vector3(Xincrement, jumpHeight, 0) * jumpSpeed * Time.deltaTime;
}
else if (Input.GetKeyDown(KeyCode.A))
{
GetComponent<Rigidbody>().velocity = new Vector3(0, jumpHeight, Zdecrement) * jumpSpeed * Time.deltaTime;
}
}
}