When i start a game and click more times (GetMouseButtonDown(0)) some of the clicks don’t work… i really dont know why? Is it just a lag on my PC or in unity… or it’s something with the script
…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerScript : MonoBehaviour
{
private bool isInGame = false;
private bool isGameOver = false;
private Rigidbody2D myRB;
Vector2 tempPos;
private bool isRight = false;
private void Start()
{
myRB = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
if (Input.GetMouseButtonDown(0)&& isRight && !isGameOver)
{
tempPos = transform.position;
tempPos.x += 2.0f;
transform.position = tempPos;
print("isRight");
isRight = false;
}
else if (Input.GetMouseButtonDown(0)&& !isRight && !isGameOver)
{
tempPos = transform.position;
tempPos.x += -2.0f;
transform.position = tempPos;
print("!isRight");
isRight = true;
}
if (!isInGame)
return;
}
public void InitGame()
{
isInGame = true;
}
void OnCollisionEnter2D (Collision2D other)
{
if (other.collider.tag == "Enemy")
{
FindObjectOfType<GameScene>().GameOver();
FindObjectOfType<CarsSpawner>().GameOver();
isGameOver = true;
}
}
}