MouseOver Entity
From Blue Mars Developer Guidebook
Overview
This script shows how you can detect mouseover enter and exit over entities.
Usage
- Install this entity class
- edit the OnMouseEnter and OnMouseExit with the behavior you want (apply a highlight material, play a sound, popup text or HUD display...)
- drag an instance of this entity into your scene and invoke the Start functon (e.g. with a trigger)
- remove debug messages if you want (probably after you make sure it works)
As with other uses of ARMousePickEntity and similar functions, test it in the Blue Mars client, as the raycast results are off with respect to the screen in the Editor.
Code
MouseOverEntity = {
currentEntity, -- save the current moused over entity
}
function MouseOverEntity:Start()
ARDebug(3)
ARDebugMessage("mouseover active!")
self:Activate(1) -- make sure OnUpdate is called
end
function MouseOverEntity:OnUpdate(deltaTime)
local entity = ARMousePickEntity()
if (entity ~= self.currentEntity) then
if self.currentEntity then
self:OnMouseExit()
end
self.currentEntity = entity
if self.currentEntity then
self:OnMouseEnter()
end
end
end
function MouseOverEntity:OnMouseEnter()
ARDebugMessage("Entering "..self.currentEntity:GetName())
-- apply your mouseover behavior with currentEntity
end
function MouseOverEntity:OnMouseExit()
ARDebugMessage("Exiting "..self.currentEntity:GetName())
-- cleanup any mouseover behavior with currentEntity
end
