Hi,
I’m creating a 2D game that require players to touch on a specific cell on screen to earn points, there’re 20 of incorrect cells and 2 correct cells. The players have to touch it fast as the screen will change each interval time (0.2s-0.4s)
The problem arises when the game runs on slow phones (3gb ram, Snapdragon 439). The screen changes faster (~0.2s each change) and the game sometimes doesn’t respone to players touches. I guess there’s something slow in checking the touch.
TouchHandler.cs
void Awake()
{
playerInput = GetComponent<PlayerInput>();
touchPressAction = playerInput.actions["TouchPress"];
touchPositionAction = playerInput.actions["TouchPosition"];
}
void OnEnable() {touchPressAction.performed += TouchPress;}
void OnDisable() {touchPressAction.performed -= TouchPress;}
void TouchPress(InputAction.CallbackContext context)
{
touchPos = touchPositionAction.ReadValue<Vector2>();
Ray ray = Camera.main.ScreenPointToRay(touchPos);
RaycastHit hit;
if(Physics.Raycast(ray, out hit, 100.0f))
{
string objectTag = hit.collider.gameObject.tag;
if(objectTag == "Cell")
{
cell = hit.collider.gameObject.GetComponent<Cell>();
gameFlow.CheckMatch(cell.Row, cell.Col);
}
}
}
GameFlow.cs
public void CheckMatch(int _row, int _col)
{
if (isGameOver) {return;}
if (gridManager.GridCell[_row, _col].CellType == profileManager.TrueType)
{
HandleTrueMatch(_row, _col); //create correct effects and score++
}
else
{
HandleFalseMatch(_row, _col); //create incorrect effects
}
}
Within the above code, I’m not sure if I can make it any better. I would be very appriciated if someone can point out any flaws or make it a bit more performance
Thank you in advance
