How can I play an animation when a player looks at an object, and how would I set a distance for how far they would have to be looking at the object before it triggers the animation?
Would I use raycasting? can anyone give me an example?
You probably want something like this:
RaycastHit hitInfo;
Ray ray = new Ray(transform.position, transform.forward);
bool didRayHit = Physics.Raycast(ray, out hitInfo, 10f);
if (didRayHit)
{
print("I am a 10 unit long ray hitting " + hitInfo.transform.name);
//hitInfo.doAnimationStuffHere;
}
the float 10 in the physics.raycast is the length of the ray. change it to any float value to change the length of the ray.