My character is supposed to slow down when the button is held down I have spent days trying to fix it can someone please help
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class SlowDownScript : MonoBehaviour
{
private Rigidbody2D self;
public float moveSpeed;
public float switchTime;
public float changeSpeed;
private bool gameOver = false;
public int seconds = 0;
public Text clock;
void Start()
{
self = GetComponent<Rigidbody2D>();
InvokeRepeating("SwitchDirections", switchTime, switchTime * 2);
StartCoroutine(Count());
}
void UpdateClock()
{
seconds += 1;
clock.text = "Time: " + seconds;
}
void SwitchDirections()
{
moveSpeed *= -1;
}
void Update()
{
self.velocity = new Vector2(moveSpeed, 1f);
if (Input.GetMouseButtonDown(0))
{
self.velocity = new Vector2(moveSpeed, 0.5f);
}
}
void FixedUpdate()
{
self.velocity = new Vector2(moveSpeed, 1f);
if (Input.GetMouseButton(0))
{
self.velocity = new Vector2(moveSpeed, 0.5f);
}
else
{
Time.timeScale = 1f;
}
}
IEnumerator Count()
{
while (gameOver == false)
{
yield return new WaitForSecondsRealtime(1);
UpdateClock();
}
}
}