Character move speed not working
I'm very new to unity and c# and so I started my first project a few weeks ago and when you hold left click the player/character is supposed to slow down but it wouldn't I've tried everything I can think of Thanks in advance
Code
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.GetMouseButton(0))
{
new Vector2(moveSpeed, 0.5f);
}
}
void FixedUpdate()
{
self.velocity = new Vector2(moveSpeed, 1f);
if (Input.GetMouseButton(0))
{
new Vector2(moveSpeed, 0.5f);
}
else
{
Time.timeScale = 1f;
}
}
IEnumerator Count()
{
while (gameOver == false)
{
yield return new WaitForSecondsRealtime(1);
UpdateClock();
}
}
}
Comment
Answer by Jacob1_23 · Jan 21, 2021 at 08:53 PM
Have you tried using (Input.GetMouseButton(0)) as an int instead of just 0
Your answer
Follow this Question
Related Questions
How do i use lines to calculate triangles on mesh?? 0 Answers
How do you stop capsule from going through walls? 1 Answer
Delete object with key within Trigger 1 Answer
How do I Instantiate a prefab at the x axis position of where the UI button was clicked 1 Answer
How do i create Tangents on a spline?? 0 Answers