Basically like Swing Copters where you tap the screen the characters flies right, then when you tap again he switches and flies left, like that. Im having trouble getting that to work. I’m getting stuck because my character moves one way and I have to hold the space bar to move him back or it won’t go the direction I want to at all. Any help is appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Swingplay : MonoBehaviour
{
public float speed = 3f;
private bool gameStart = false;
public bool goingRight = false;
void FixedUpdate()
{
if (Input.GetKey("space") && goingRight == false)
{
goingRight = true;
}
if (Input.GetKeyDown("space") && goingRight == true)
{
goingRight = false;
}
if (goingRight == true)
{
transform.Translate(-Vector3.left * speed * Time.deltaTime);
}
else
{
transform.Translate(-Vector3.right * speed * Time.deltaTime);
}
}
//transform.Translate(-Vector3.left * speed * Time.deltaTime);
}