Question by
La-Spada · Oct 02, 2016 at 09:30 AM ·
gameobjectflickering
Gameobject flickers
I am using LeapMotion in Unity, and I want a GameObject to be visible only when the hands are in a certain position, in this case only when the hand has all the fingers extended and the palm is facing up. And that object has to follow the position of the palm while it is visible. The script works, but i can't see properly the object, it flickers like this:
https://media.giphy.com/media/6v4Q66zNzRlLy/giphy.gif
There is the script that shows the object.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
namespace Leap.Unity
{
public class SeeObject : MonoBehaviour
{
public Text textr;
public Text textl;
public GameObject sphere;
public IHandModel HandModel_L = null;
public IHandModel HandModel_R = null;
bool openPalm,upPalm;
int openp, upp;
Vector3 palmPos= new Vector3(0,0,0);
public void Awake()
{
sphere.SetActive(false);
}
public void Update()
{
if(openp==1 && upp==1)
{
palmPos = HandModel_L.GetLeapHand().PalmPosition.ToVector3();
}
else if (openp == 2 && upp == 2)
{
palmPos = HandModel_R.GetLeapHand().PalmPosition.ToVector3();
}
sphere.transform.position = palmPos + new Vector3(0, 0.1f, 0);
ShowSphere();
}
public void IsOpenPalm(int open) //open=0 not open, open=1 leftHand, open=2 rightHand
{
openp = open;
if (open > 0)
{
openPalm = true;
textr.text = "open";
}
else
{
openPalm = false;
textr.text = "close";
}
}
public void IsPalmUp(int up) //up=0 is down, up=1 leftHand, up=2 rightHand
{
upp = up;
if (up >0)
{
upPalm = true;
textl.text = "palm up";
}
else
{
upPalm = false;
textl.text = "palmo down";
}
}
private void ShowSphere()
{
if(upPalm && openPalm)
{
sphere.SetActive(true);
sphere.transform.position = palmPos + new Vector3(0, 0.1f, 0);
}
else
sphere.SetActive(false);
}
}
}
Comment
Best Answer
Answer by La-Spada · Oct 06, 2016 at 08:23 AM
FIXED In the Editor I accidentally set two right hands, and of course the script didn't work.
Your answer
![](https://koobas.hobune.stream/wayback/20220612093837im_/https://answers.unity.com/themes/thub/images/avi.jpg)