Answer the question
In order to leave comments, you need to log in
How to move an object a certain distance over time?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cubeBehavior : MonoBehaviour
{
// Start is called before the first frame update
GameObject Player;
Queue<int> queue = new Queue<int>();
private Vector3 startPos;
private Vector3 endPos;
private float distance = 30f;
private float lerpTime = 5;
private float currentLerpTime = 0;
private bool keyHit = false;
void Start()
{
startPos = Player.transform.position;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))//очередь создана
queue.Enqueue(1);
if (Input.GetKeyDown(KeyCode.LeftArrow))
queue.Enqueue(2);
if (Input.GetKeyDown(KeyCode.RightArrow))
queue.Enqueue(3);
if (Input.GetKeyDown(KeyCode.DownArrow))
queue.Enqueue(4);
if (Input.GetKeyDown(KeyCode.Space))
Play();
}
public void Play()
{
foreach (int number in queue)
{
if (number == 1)<b>//нужна помощь здесь</b>
<b>{</b>
<b>endPos = Player.transform.position + Vector3.forward * distance;
keyHit = true;
if (keyHit == true)
{
currentLerpTime += Time.deltaTime;
if (currentLerpTime >= lerpTime)
{
currentLerpTime = lerpTime;
}
}
float Perc = currentLerpTime / lerpTime;
Player.transform.position = Vector3.Lerp(startPos, endPos, Perc);
}</b>
else if (number == 2)
{
transform.Rotate(0, 90, 0);
}
else if (number == 3)
{
transform.Rotate(0, 45, 0);
}
else if (number == 4)
{
print("4");
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question