- Home /
iOS Polygon button not working with yield WaitForSeconds
Using Javascript in iOS. Trying to build a simple GUI system using Polygons with colliders as buttons. I've got the Input.touch ray firing just fine but any yield WaitForSeconds attached to it won't work. Currently, the polygon button does records the hit by scaling it a bit larger, but WILL NOT continue further. It should continue on to yield WaitForSeconds (.2), then put it back to it's original scale. Should look like a regular button press.
Also, I think this seems like an efficient way to handle the interface due to all button textures on one map rather than separate GUITextures or OnGUI. Also the fact that polygons scale properly with the screen size (3G,4G,iPad) while the others require extra code to scale properly. Let me know if it actually sucks for any performance reasons.
Code attached to camera to draw a ray:
function Update ()
{
for (var Touch : Touch in Input.touches)
{
if (Touch.phase == TouchPhase.Began)
{
var ray = Camera.main.ScreenPointToRay (Touch.position);
Debug.DrawRay (ray.origin, ray.direction * 200, Color.yellow);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit))
{
hit.collider.SendMessageUpwards("Activate", SendMessageOptions.DontRequireReceiver);
}
}
}
}
Code attached to polygon button: Activate_Button.js
var scaleFactor = 1.1;
var thisScaleX = 0.0;
var thisScaleY = 0.0;
function Awake()
{
//Record the original size of polygon
thisScaleX = transform.localScale.x;
thisScaleY = transform.localScale.y;
}
function Activate ()
{
// THIS WORKS FINE...
transform.localScale = Vector3(thisScaleX, thisScaleY,1) * scaleFactor;
// … BUT WON'T CONTINUE ON TO THIS.
yield WaitForSeconds (0.2);
transform.localScale = Vector3(thisScaleX, thisScaleY,1);
Debug.Log("Button Pressed")
}
I have tried numerous other ways including StartCoroutine, unhiding another pre-scaled poly button, etc. and nothing works. Seems to me that the polygon button script only fires for the exact frame on which the ray hits it. Since yield has to do with a longer time factor, it is disregarded. At least that's all I can think of.
Any words of advice are greatly appreciated.
- UPDATE -
After some tests, I noticed that Frames Per Second are not registering in some of my scenes. This problem is a direct result of yield WaitForSeconds not working. See the link below for tests I performed to figure out that they weren't registering. I still DO NOT have a direct fix aside from exporting all my scenes and importing into a new project file.
http://answers.unity3d.com/questions/204885/frame-counter-not-registering.html
Your answer
Follow this Question
Related Questions
Frame counter not registering - Component missing? 1 Answer
Low FPS rate. Can't find the problem. Followed Unity's Guide 2 Answers
Mobile GUI Buttons 1 Answer
On iOS, how do I fade out music when the user presses the home button? 1 Answer
How do I set up a GUITexture as a functional button? 4 Answers