How can I isolate just the character to slow down
So I'm just a beginner at unity and I'm building a project that you have to dodge balls falling from the sky and the character goes back and forth across the screen, but my problem is whenever the key button is held it doesn't work Here's the code if anyone has any idea of how to fix it 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(); 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)) { Time.timeScale = 0f; Time.timeScale = 1f; } } void FixedUpdate() { self.velocity = new Vector2(moveSpeed, -1f); if (Input.GetMouseButtonDown(0)) { Time.timeScale = 0.5f; Time.timeScale = 1f; } else { Time.timeScale = 1f; Time.timeScale = 1f; } } IEnumerator Count() { while (gameOver == false) { yield return new WaitForSecondsRealtime(1); UpdateClock(); } }
Your answer
Follow this Question
Related Questions
Physics2D.OverlapBox (C#) 0 Answers
How to change Sprite Image when it reaches 90 degrees? 0 Answers
Can not load the next scene 0 Answers