private void Movement()
{
transform.Translate(Speed * Time.deltaTime, Speed * Time.deltaTime, 0);
}
public class Move : MonoBehaviour
{
public float moveSpeed = 1f;
public Vector2 spawnPoint = Vector2.zero;
public Quaternion rotationPoint;
public int moveTimer = 2;
public float timer;
public Vector2 lastPos = Vector2.zero;
public Vector3 previouslyPos = Vector3.zero;
// Start is called before the first frame update
void Start()
{
spawnPoint = new Vector2(0, 0);
transform.position = spawnPoint;
}
// Update is called once per frame
void Update()
{
timer += Time.deltaTime;
if (Input.GetKeyDown("w"))
{
moveTimer = 1;
}
if (Input.GetKeyDown("s"))
{
moveTimer = 2;
}
if (Input.GetKeyDown("d"))
{
moveTimer = 3;
}
if (Input.GetKeyDown("a"))
{
moveTimer = 4;
}
if (timer >= 0.25f)
{
if (moveTimer == 1 & spawnPoint.y < 4)
{
spawnPoint.y += moveSpeed;
transform.position = spawnPoint;
rotationPoint = Quaternion.Euler(0, 0, 180f);
transform.rotation = rotationPoint;
}
if (moveTimer == 2 & spawnPoint.y > -5)
{
spawnPoint.y -= moveSpeed;
transform.position = spawnPoint;
rotationPoint = Quaternion.Euler(0, 0, 0);
transform.rotation = rotationPoint;
}
if (moveTimer == 3 & spawnPoint.x < 6)
{
spawnPoint.x += moveSpeed;
transform.position = spawnPoint;
rotationPoint = Quaternion.Euler(0, 0, 90f);
transform.rotation = rotationPoint;
}
if (moveTimer == 4 & spawnPoint.x > -6)
{
spawnPoint.x -= moveSpeed;
transform.position = spawnPoint;
rotationPoint = Quaternion.Euler(0, 0, 270f);
transform.rotation = rotationPoint;
}
timer = 0;
if (spawnPoint != lastPos)
{
previouslyPos = lastPos;
previouslyPos.z += 0.10f;
}
lastPos = spawnPoint;
}
}
}