Hi all,
Trying to add some more interface functionality for my project and decided I want to make AI Conversants (and other interactable components) highlighted when I raycast them.
I can’t seem to figure out a way in the IRaycastable interface to detect when the raycast has stopped.
I’ve added the following method to HandleRaycast in my AI Conversant (though I might just make a new component with IRaycastable for it called Highlighter or something):
private void HighlightComponent()
{
if (meshRenderer != null && meshRenderer.materials.Length > 1)
{
meshRenderer.material = meshRenderer.materials[1];
}
}
So part 1 works great for turning it on, but it won’t switch back because I need to call the material change again.
What is the right way to do this?
The only place that handles when the casting stops is player controller Update() method (for cursors),
Other place I could think of is the components own Update() method,
but I don’t think I should check it every frame. or should I?
And i’m still not sure about how to detect when the raycast stopped
Current player controller Update():
private void Update()
{
CheckSpecialAbilityKeys();
if (InteractWithUI())
{
SetCursor(CursorType.UI);
return;
}
if (health.IsDead())
{
SetCursor(CursorType.None);
return;
}
if (InteractWithComponent()) return;
if (InteractWithMovement()) return;
SetCursor(CursorType.None);
}
Would very much like to learn any good way to detect the frame in which the raycast stopped hitting the IRaycastable?
Or Am I going about it the wrong way?
Should I make a IHighlightable interface and check for that in the player controller?
(I am following the 4 sections of course project so the main parts of my code are the same as at the end of Dialogue&Quests).