Thanks AggrorJorn for your answer.
I tried both , the prefab and with the model via script, but the result is the same.
This is the script that is attached to the medikit model,it's basically like the push button trigger with added instructions to give energy.
I added the collision function () to test if it works and the result is that it works. Only use () function does not work.
Script.enabled=true--bool "Enabled"
Script.soundfile=""--path "Sound" "Wav Files (*.wav):wav"
Script.Energy=20 --int "proiettili da dare"
function Script:Start()
if self.soundfile then
self.sound = Sound:Load(self.soundfile)
end
self.entity:SetCollisionType(Collision.Prop)
self.entity:SetMass(10)
end
function Script:Use(Player)
if self.enabled then
if self.sound then self.entity:EmitSound(self.sound) end
self.component:CallOutputs("Use")
if Player.health < Player.maxHealth then
Player:GiveHealth(self.Energy)
self.entity:Release()
else
Player.timeStartandDuration = Time:GetCurrent() + 2000
Player.hemax=true
end
end
end
function Script:Collision(entity, position, normal, speed)
if self.enabled then
if entity:GetKeyValue("name")=="giocatore" then
if entity.script~=nil then self:Use(entity.script) end
end
end
end
function Script:Enable()--in
if self.enabled==false then
self.enabled=true
self.component:CallOutputs("Enable")
self.health=1
end
end
function Script:Disable()--in
if self.enabled then
self.enabled=false
self.component:CallOutputs("Disable")
self.health=0
end
end
function Script:Release()
if self.sound then self.sound:Release() end
end