Home > database >  How to disable touch on specific part of the screen in unity 2d Android using c#?
How to disable touch on specific part of the screen in unity 2d Android using c#?

Time:03-25

I have a drawing manager which draws lines using line renderer, what I want is that when I click on a specific area in my game, the screen should not take any input or line renderer shouldn't draw anything on that specific area.

Basically I am using a button on which I don't want any input for my line renderer. I want it (Button) to perform its own functions but when I click on the button the line renderer shouldn't work or it shouldn't draw any lines.

I couldn't find anything related to this on the internet.

Thanks in Advance!

CodePudding user response:

Maybe you can add simply UI Panel object with raycast target = enabled. Like this way you can block player's touch.

CodePudding user response:

I figured it out, basically I just used the list to check if a line has been drawn or not. The line object is stored inside the list. If the line exists inside the list the button will give response and will be interactable but if it doesn't contain any item, it will turn off the script which helps generating the lines.

Here is the code:

  if (DrawingManager.Instance.paths.Contains(DrawingManager.Instance.clone))
    {
        VehicleSimpleControl._instance.RacePress = true;
        //VehicleSimpleControl.Instance.aceleration = 3.2f;
        resetButton.SetActive(false);
        Debug.Log("racepress true");
    }
    else
    {
        drawingManager.enabled = false;
    }
  • Related