GUI.Toggle button in Unity does not close pop up window - android

I have the following script to open a GUI.Window as a pop up with a toggle button. In Unity3d editor player the script run o.k., with the window open-close on toggle button click.
As I compile the scene to my Android device, the script runs, but I can only open the GUI.Window with touching toggle button, and I cannot close it on touching again the button.
Take a look at the script, and give me some advise why is that happening, what is wrong with this UnityScript? Thank you all in advance.
Here is the script:
#pragma strict
private var doWindow0 : boolean = false;
var aTexture : Texture;
var wTexture : Texture;
// Make the contents of the window.
function DoWindow0 (windowID : int) {
GUI.color = Color.cyan;
GUI.Box (new Rect (10,10,415,210),wTexture);
}
function OnGUI () {
if(!aTexture) {
Debug.LogError("Please assign a texture in the inspector.");
return;
}
// Make a toggle button for hiding and showing the window
doWindow0 = GUI.Toggle(Rect(210,210,70,20), doWindow0, aTexture);
//doWindow0 = GUI.Button (new Rect (10,10,100,20), doWindow0, "InfoBox");
// Make sure we only call GUI.Window if doWindow0 is true.
if (doWindow0)
GUI.Window (0, Rect (30,0,420,215), DoWindow0, "InfoBox");
// Make the windows be draggable.
GUI.DragWindow (Rect (0,0,10000,10000));
}

Well, since nobody has posted anything yet, let me crarify the situation. After extented research with "trial and error" and step by step running (& debuging) the posted script, I have finaly made it, to find the culprit.
There was nothing wrong in the js code. It was a GameObject, the device rendered on a lower layer, besides the layer of the toggle button.
It seems that the graphics chip of my android device, isn't strong enough to render 2d and 3d graphic simultaneously with user interaction. Having replaced the 3d GameObject with a high definition 2d image, made everything work ok.

Related

Unity3D : Raycast Issues on Android Build

I'm using Unity 3D for developing 3D desfense game.
I made a monster that can take agro from intruders of map, making them occupied while being vulnerable to other attacks. I wanted to make monster can be moved when it's touched once.
Process: touch the monster → touch the destination → monster moves to the destination
I wanted my monster to move through the entire map, but can take intruder's agro
only when they're on the road. I'm currently using Raycast to make this happen, and I'm stuck.
It works just fine on Unity, but when it's on a build and played on the phone, monster can't recognizes the touch or can't recognizes the point where I touched.
if (IsClickMonster)
{
if (Input.GetMouseButtonDown(0))
{
Ray MoveClick = cam.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(MoveClick, out ClickedPosition, float.MaxValue, whatCanbeClickedOn) && ClickedPosition.collider.gameObject.CompareTag("monster") == false)
{
Debug.Log("Monster is Moving!");
clickEffect.transform.position = new Vector3(ClickedPosition.point.x, ClickedPosition.point.y + 1.0f, ClickedPosition.point.z);
StopCoroutine("MonsterMove");
IsMoving = true;
StartCoroutine("MonsterMove");
}
else
{
clickEffect.SetActive(false);
StopCoroutine("MonsterMove");
IsClickMonster = false;
return;
}
}
}
else
{
return;
}
↑ Picture of Moving the Skull Soldier. White dot(clickEffect) is where Player touched(ClickedPosition).
Physics.Raycast(MoveClick, out ClickedPosition, float.MaxValue, whatCanbeClickedOn)
Even though I'm using the "whatCanbeClickedOn" layermask, I wonder what can I do to avoid this from happening on mobile build.
In my experience with android, when something doesnt work well in android could be either you have some error or warning on execution that did not trigger on unity just by chance or maybe the phone is not capable of handling the game like it moves too many polygons or lights and it cant handle it well then starts making odd things, try checking the warnings in unity and see if any error appears too of course, thats my best bet

How to make a game object appear through triggers from 3 different game objects

I am developing an AR app using Unity3D and Vuforia.
I did all the basics of AR and now in the process of completing it.
However, I am currently stuck at the triggers part.
I have 3 flashcards (Number 1, Number 2, Plus). I have put box colliders in each one of them and rigidbodies in Number 1 and Number 2. The Plus card acts as the trigger.
Right now, I am trying to make the game objects in each card disappear when triggered, and a fourth game object will appear when the trigger happens. The fourth game object is the result of the addition (i.e. 1 + 2 = 3).
I have developed the following code. The game objects are triggered according to the tags I have given them. The game objects disappear, but the fourth game object doesn't appear. What have I done wrong here?
#pragma strict
var mathplus : GameObject;
var sphere01 : GameObject;
var sphere02 : GameObject;
var result03 : GameObject;
function Start(){
sphere01.SetActive(true);
sphere02.SetActive(true);
mathplus.SetActive(true);
result03.SetActive(false);
}
function OnTriggerEnter (other : Collider) {
Debug.Log("Object entered the trigger.");
if (other.tag == "number01" && other.tag == "number02"){
mathplus.SetActive(false);
sphere01.SetActive(false);
sphere02.SetActive(false);
result03.SetActive(true);
}
}
function OnTriggerExit (other : Collider) {
Debug.Log("Object exited the trigger.");
mathplus.SetActive(true);
sphere01.SetActive(true);
sphere02.SetActive(true);
result03.SetActive(false);
}
The game objects in the Number cards are called "sphere", the game objects in the Plus card is called "mathplus", and the fourth game object is called "result03".
I hope someone can help rectify this problem.
Thanks and regards.
You made a small mistake.
It is because the fourth card is disabled, so the collider of it is disabled too.
Your logic is right, what you should do is invisible the card4, not disable it
Disable Mesh Rendering To Hide A Gameobject
GetComponent(MeshRenderer).enabled = false;
It is c# script, sorry, I do not know very about unity js.😆
You can get more detail from invisible Gameobject and disable Gameobject

Samsung Gear controlls - Unity 3D

I use Unity 3D with Samsung Gear. I have a working OVRPlayerController in my scene but I am having difficulties mapping the oculus tap, swipe and return button.
I have tried with something like:
if (Input.GetMouseButtonDown(0))
{
Debug.Log("input detected");
}
And with this I detect the tap encircled in red
I have tried also something like:
if (OVRInput.Get(OVRInput.Button.PrimaryThumbstick))
{
Debug.Log("Input detected");
}
Or :
if (OVRInput.Get(OVRInput.Button.One))
{
Debug.Log("Input detected");
}
But nothing seems to work. Is there any documentation that explains how is the input mapped on Samsung Gear that I encircled in yellow ? Does anyone have experience with this or can maybe guide me to some useful documentation on this matter ?
Cheers
My project settings for input:
For swipes, you can get the current Vector2 on the touchpad (either the HMD and/or the incoming remote controller touchpad) by using:
CurrentVector = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad);
as for the back button, it is accessible using OVRInput.Button.Back either on Get, GetDown or GetUp. But know that a 2 seconds long back press is reserved for the Universal Menu and should not have any implications inside your game or app.

Unity3d Gyroscope look around

I'm new to Unity and I am trying to build a solar system exploration app through unity. I have the environment set up, and now all I need is the ability to look around (via tilting and moving the phone itself, which is android) smoothly. I have the ability to look around, but if I do a complete 180, it seems to invert the physical orientation of the phone with the visual movements in game, e.g. if I have turn 180 degrees, if I tilt the phone down it shifts my vision in game to the right, up results in visual shift to the left. Here is the code I have thus far:
#pragma strict
private var quatMult : Quaternion;
private var quatMap : Quaternion;
function Start () {
Input.gyro.enabled = true;
}
function Update () {
#if UNITY_ANDROID
quatMap = Input.gyro.attitude;
#endif
transform.localRotation = Quaternion.Euler(90, 0, 0) * quatMap * Quaternion(0,0,1,0) /*quatMult*/;
}
Any help is greatly appreciated. Thanks.
This should be what you're looking for: https://gist.github.com/chanibal/baf46307c4fee3c699d5. Just drag it to the camera and it should work.
You might want to remove the reset on touch part (Input.touchCount > 0 in Update) and debug information (the OnGui method).

Window already focused, ignoring focus gain of For raising height of sprite the preferences

I know this has been asked before and I went through all the answers and nope this ain't that, and yes I have the activity named in the manifest so it's not that.
Here's my problem:
I have a sprite moving across the screen and when in the window where you choose the livewallpaper, I have a preference that lets the user choose the height (so they can move the sprite up or down) the only problem is the sprite is constantly moving so when they use the seekbar to move the sprite up or down I get the old 'Window already focused, ignoring focus gain of" Now if I go out and come back in again of course this stop and restarts it and the new preference hight is already in their so it moves to the new height then but not in the live preview.
Here is the sprite code:
private void addShipOne() {
int heightPosition = (screenSized / 2) - (screenSized / /*this.bigShipHeight*/gettheFreakingHeight());
int widthPosition = 0;
Point startPoint = new Point(widthPosition, heightPosition);
this._shipone.add(new SpaceShipOne(this._context, this, startPoint, 125));
(sorry about the method name I was using to test a quick version I was a bit frustrated at that point) lol
It then goes into an OnDraw method then into the render to render it all.
public void render(){
Canvas canvas = null;
try{
canvas = this._surfaceHolder.lockCanvas(null);
synchronized (this._surfaceHolder) {
this.onDraw(canvas);
}
}finally{
if(canvas != null){
this._surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
I have another preference that allows the user to choose the frequency of the ships appearing it works fine but it goes from left to right and changes ships then so it updates the frequency then, but the height one doesn't work, I tested the log to make sure the height int goes through and it does so its not that, the only thing I can come up with is the maybe add this when the ship turns left or right, but it does not work while its moving by the looks of it.
this.bigShipHeight is where the new height value goes into ( I was just testing it another way with the gettheFreakingHeight() (I used an if else statement for that method that used the frquency preference instead which does work nicely.
Just to add the full code part.
In the onDraw(Canvas canvas)
I render the _shipone as such
for (Renderable renderable : this._shipone) {
renderable.render(canvas);
}
Any help would be appreciated.
Thanks in advance
Sam
Ok I should of looked into the my sprite class first, sorry about this I answered my own question once again and it was too obvious, that's what I get for looking at the code way to long, I should walk away then come back it always is clearer then.
Just in case others run into this issue I'll put the answer.
In my sprite class which SpaceShipOne runs from I just added this
this.getSprite().setYPos(this._blimp.gettheFreakingHeight());
This updates right away with no window already focused.
I don't know why I didn't see this last night because it is the only place it can be added and be updated right away, all I had to do was set the Y position to the preference instead.
It works like a charm.
Hope this helps someone else out
Sam

Categories

Resources