I am trying to make my game have the ability to right mouse button click on web builds.
void MouseCheck()
{
if(Input.GetMouseButton(1))
{
//my code
}
}
But it doesn't get detected because when I right click in web build it shows some default options such as full screen.
This is a bit tricky, but not impossible.
You need to make changes on the built's HTML. This is how you would do it:
var params =
{
disableContextMenu: true,
};
This parameter will notify Unity Web Player whether it should display the ContextMenu or not. This in turn prevents the context menu from appearing, which then allows your game to check for Right-Mouse Clicks.
Here is a link to all the customization you can do to the HTML file: Unity WebPlayer's Behaviours.
It is important that you include the C# code which does the actual right click checks happen.
if(Input.GetMouseButtonDown(1))
{
// Code here.
}
This was added for future readers who might benefit from this part
Related
I am Developing a FPS Game and I am using The FPSController that comes with the Standard Assets. I am developing a Gamepad controller to control the mobile game.
After configuring all inputs of the controller I want to replace the code as following:
if (!m_Jump)
{
m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
}
The code should be like following:
if(Application.platform == RuntimePlatform.Android)
{
if (!m_Jump)
{
m_Jump = Input.GetButtonDown("Joystick A");
}
}else{
if (!m_Jump)
{
m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
}
}
What is the best way to modify the FPS Controller Scripts and add These Inputs?
Thanks in advance.
You can go around this in a way that does not require you to edit or add any aditional code.
Under Edit>Project Settings > Input you can find the InputManager and "axis". In here you will find all the pre-defined input values and their corresponding buttons. If you unfold the Input Axis "Jump" You'll see it has a variable called "Positive button" which is by default space, and an empty "alternative button". If you add your desired button to the alternative button sectiong it will trigger the CrossPlatformInputManager.GetButtonDown("Jump"); action upon pressing the corresponding button on your gamepad.
you can also if you prefer extend the list and add your own triggers.
The input manager offers out of the box support for keyboard and mouse, joystick, and gamepad more information can be found in the docs here
The advantage of doing this is that this requires no additional code or conditions. Which is probably the most optimalised way to go aroung it
So I'm using the AttachToController script to attach a window floated on top of the controller - which works great. In the script that calls up the window, I figure out which hand pressed the controller's menu button and set the Handedness field appropriately (Left or Right). The problem I'm trying to solve is this: Let's say the user clicks on the right controller's menu button and then later on, the left menu button is clicked. The problem I'm experiencing is that even though I've altered the Handedness field, the window still appears attached to the right controller.
private void InteractionManager_InteractionSourcePressed(InteractionSourcePressedEventArgs args)
{
hand = args.state.source.handedness;
...
}
private void SetHandednessAndActivate(GameObject go)
{
AttachToController script = go.GetComponentInChildren<AttachToController>();
if (script != null)
{
script.Handedness = hand;
}
go.SetActive(true);
}
Just to be clear, if the user clicks the left controller menu button first, the window is always on the left and the same holds true for the right controller. What I want is for the window to move to whichever controller is used.
Instead of
script.Handedness = hand;
Use
script.ChangeHandedness(hand);
All the other bits are handled by the script.
We have a Xamarin app (Android) that at one stage opens up a web view (Webkit.Webview not Forms.Webview). This directs the user to a page on a third party site which has been set up for us.
Firstly - on certain input fields the keyboard which shows up is the wrong one - we are expecting a dismissable keyboard (i.e. "Done" in the bottom corner, not a "Submit"). I know this can be changed but not sure what is the correct way to do this. Does it have to be the metadata/text inputs on the web page that is changed? If so - what needs to be modified per text box entry on the html of the page? Just the type? i.e:
<input type="email">
Secondly, rather than wait for the third party to fix the page, is there a way we can force the webview to always open a certain keyboard type?
We have an option of intercepting the keyboard key presses and trying to dismiss the keyboard on return press at the minute. But would prefer not to put a hack in that intercepts every key press.
Appreciate the help, not sure what the way forward is here.
Thanks
From the comments: To your second question about forcing a keyboard button, you can check out this link which describes how to override OnCreateInputConnection to specify the Keyboard Enter Button type.
public class MyWebView : WebView {
...
public override IInputConnection OnCreateInputConnection (EditorInfo outAttrs) {
var inputConnection = base.OnCreateInputConnection (outAttrs);
// outAttrs.ImeOptions in Xamarin only allows ImeFlags but it also should allow ImeActions
outAttrs.ImeOptions = outAttrs.ImeOptions | (ImeFlags)ImeAction.Next;
return inputConnection;
}
}
That will not dismiss your keyboard when tapped though since it is meant to take the user to the next input. Hopefully someone else can come along and either provide a better answer or give a good way to dismiss the keyboard in this situation without hacking something together.
I have three buttons, when you tap one button, a panel with a text appear.
The problem is when I attached the script, nothing happens.
The "click" is registered but the the panel never appears.
My script is attached to each of the button and is something like this:
public GameObject panel; //i use to put the panel in unity
bool selected = false;
void Start () {
panel.SetActive(false);
}
void OnSelect() {
selected = !selected;
panel.SetActive(true);
}
I probably have to do something else with the panel but I can't figure it out.
Do it like this:
(1) Add the canvas to your project
(2) BIG TIP - be sure to select Scale with screen size.
That's the only one you ever use. Unity accidentally set the wrong default there, they have not fixed it yet.
(3) In your Canvas, add a BUTTON Make it say perhaps "Test"
(3) In your Canvas, add another BUTTON Make it say perhaps "Another Test"
(4) Make a script something like this...
public class MainScreen:MonoBehaviour
{
public void UserClickedTest()
{
Debug.Log("test..");
}
public void UserClickedAnotherTest()
{
Debug.Log("another test..");
}
}
(5) put ONE copy of that script on ANY object you like. You can put it on your camera, on the canvas, or anywhere else that makes sense
For now let's say you put it on your CAMERA object, for example.
(6) Click on the button "Test" .....
And do this ...
click the PLUS button under OnClick
you see the slot that says "_main" in this example. DRAG your CAMERA item from HEIRARCHY, to that slot
Using the drop down menu:
select the "UserClickedTest()" function ...
good eh?
Now for the other button, do the same but select the "UserClickedAnotherTest()" function.
You're done! Run and test!
You can't use the OnSelect system unless you use ISelectHandler and more stuff: it is difficult for beginners. I strongly recommend the OP masters the simpler technique I explain here. Enjoy!
Maybe you attached the script to the panel. If so, your scripts can not be executed as long as your GameObject is SetActive(false).
I hope I was able to help you.
I asked a question recently about how to disable the back button is Android, after a while I got it working with these lines of code
public override void OnBackPressed ()
{
// base.OnBackPressed (); /* Comment this base call to avoid calling Finish() */
// Do nothing
}
And just recently someone commented this
Disabling the back button is counter-intuitive and breaks the device
usage contract imposed by Android. So i suggest you rethink.
-Question-
What would be a possible change to this? I dont want to be able to press the back button when playing my quiz game because that would make be able to cheat. New to android Development
Instead of simply making the back button do nothing, you could have it create a popup asking something along the lines of "Are you sure you want to leave the quiz? (This will count as a loss)". And have it take the user back to the main page of your app if he confirms (instead of back to the previous page).
Why not imitate what many websites do and make it so going 'back' to a page works but doesn't display any information?
It depends on your code, but perhaps you can make your buttons and text (or whatever it is you don't want them interacting with) change to be unseen whenever they move on to a new page. Or just throw up a message that says 'You can't do that' to cover the page that they'll only ever see if they go back to view it again.