Home>

How do I react to the time I saw an object?

I'm currently tracking my eyes using FOVE0.
Now when you see this object for a moment, it reacts.

What I want to do is set it to react when I see an object in it for 1 second.

I want to make a program that can react by looking at it for more than 1 second, not just by passing through the object with a gaze. .

The point seen in the script below shines.

using UnityEngine;
public class FOVELookSample: MonoBehaviour {
    public Light attachedLight;
    public FoveInterfaceBase foveInterface;
    private Collider my_collider;
    private Material material;
    private bool light_attached = false;
    void Start () {
        my_collider = GetComponent<Collider>();

        if (attachedLight)
        {
            light_attached = true;
            attachedLight.enabled = false;
        }
        material = gameObject.GetComponent<Renderer>(). material;
        if (material == null)
            gameObject.SetActive (false);
    }
    void Update () {
        if (foveInterface.Gazecast (my_collider))
        {
            material.EnableKeyword ("_ EMISSION");
            if (light_attached)
            {
                material.SetColor ("_ EmissionColor", attachedLight.color);
                attachedLight.enabled = false;// Light is on
                DynamicGI.SetEmissive (GetComponent<Renderer>(), attachedLight.color);
            }
        }
    }
}

Thank you.
I am a beginner in both C # and Unity.

  • Answer # 1

    I don't have FOVE, and it is my idea that it might be like this. How is it?

    public float GazingTime = 1.0f;// Staring time ... Set how many seconds to keep watching
        private float currentGazingTime;// Field for counting staring time
        private bool lightEnabled;// field indicating whether the light is currently on
        void Update ()
        {
            if (lightEnabled)
            {
                // If the light is on ...
                if (! foveInterface.Gazecast (my_collider))
                {
                    // If Gazecast did not hit, the line of sight was lost and the light was turned off
                    lightEnabled = false;
                    currentGazingTime = GazingTime;
                    material.DisableKeyword ("_ EMISSION");
                    if (light_attached)
                    {
                        material.SetColor ("_ EmissionColor", Color.black);
                        attachedLight.enabled = false;
                        DynamicGI.SetEmissive (GetComponent<Renderer>(), Color.black);
                    }
                }
            }
            else
            {
                // If the light is off ...
                if (foveInterface.Gazecast (my_collider))
                {
                    // If Gazecast hits ...
                    // decrease currentGazingTime by elapsed time
                    currentGazingTime-= Time.deltaTime;
                    if (currentGazingTime<= 0.0f)
                    {
                        // When currentGazingTime becomes 0 or less, keep staring and GazingTime seconds have passed, so turn on the light
                        lightEnabled = true;
                        material.EnableKeyword ("_ EMISSION");
                        if (light_attached)
                        {
                            material.SetColor ("_ EmissionColor", attachedLight.color);
                            attachedLight.enabled = false;// Light is on
                            DynamicGI.SetEmissive (GetComponent<Renderer>(), attachedLight.color);
                        }
                    }
                }
                else
                {
                    // If Gazecast does not hit, the line of sight is lost, so currentGazingTime is reset to GazingTime
                    currentGazingTime = GazingTime;
                }
            }
        }