Hi
I have this script which I am using in a basic VR game. I use the reticlepointer to choose; if the person looks at an item for x seconds it kicks in the function. So this is the function called when i use the pointer enter event
public void MouseHoverLook()
{
mousehover = true;
}
the update function then waits to see if the person looks at the object long enough to kick in the given script
void Update()
{
if (mousehover)
{
Counter += Time.deltaTime;
if (Counter >= DelayStart)
{
LetsGo();
}
}
}
this works fine if I just want to start a process, but I need to use this to start/stop a buggy. So when the person looks at the buggy for x seconds it will start. They then need to be free to look around the scene, beyond the box collider on the buggy. When they look at the buggy again this should then stop it.
I have tried setting a boolean for whether the buggy is moving or not:
if (move)
{
if (Counter >= DelayStart)
{
LetsGo();
}
}
else if (!move)
{
if (Counter >= DelayStop)
{
LetsGo();
}
}
and also tried setting it up with coroutines but that didn’t work either. If I reset the counter either in mousehoverlook() or in update() it just stops the buggy from moving immediately.
The moving function is:
private void LetsGo()
// IEnumerator LetsGo()
{
// yield return null;
speedset = speed;
float distance = Vector3.Distance(PathToFollow.path_objs[CurrentWayPointID].position, transform.position)-1;
transform.position = Vector3.MoveTowards(transform.position, PathToFollow.path_objs[CurrentWayPointID].position, Time.deltaTime * speedset);
var rotation = Quaternion.LookRotation(PathToFollow.path_objs[CurrentWayPointID].position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationSpeed);
if (distance <= reachDistance)
{
CurrentWayPointID++;
}
if (CurrentWayPointID > +PathToFollow.path_objs.Count - 1)
{
if (loop)
{
CurrentWayPointID = 0;
}
else
{
mousehover = false;
}
}
}
}
This doesn’t feel very complex but I cannot work out how to do this; any help gratefully received.
thanks v much
