In general, trigger does not correctly work (perhaps I don’t know something), when using such code:
void ontriggerstay (collider other)
{
if (input.getKeydown (LootButton))
{
Debug.log ("Buttonwaspushed");
}
}
When I am in the collider of the object and click on the button – the log is duplicated (the same message is displayed 2 times), plus everything, not all pressures are generally perceived, that is, I can press 5 times, and from five clicks May not go out at all. (With all ok button, checked on others)
Answer 1, Authority 100%
could immediately put the question in this way.
Public Class Loot: Monobehaviour {
Public void Taking () {
DESTROYIMMEDIATE (GameObject);
}
}
Public Class Player: Monobehaviour {
Private List & lt; Loot & GT; _Closeloot = New List & lt; Loot & gt; ();
Private void Update () {
if (input.GetKeyDown (keycode.space) & amp; & amp; _closeloot.count & gt; 0) {
_Closeloot [0] .taking ();
_Closeloot.Removeat (0);
}
}
Private void onNigGeNTER (Collider Other) {
If (Other.getcomponent & lt; Loot & gt; ()! = NULL)
_closeloot.add (other.getcomponent & lt; loot & gt; ());
}
Private Void OnTriggereExit (Collider Other) {
If (Other.getcomponent & lt; Loot & gt; ()! = NULL)
_Closeloot.Remove (Other.getcomponent & lt; Loot & gt; ());
}
}
Answer 2, Authority 100%
Perhaps something in the first location of the documentation:
And even though not in the first paragraph, but about how input
is also written:
They have different frequencies and ontriggerstay
to put it mildly not a place for Input
.
Answer 3
found an alternative to who is interested:
void update ()
{
if (input.getKeydown (LootButton) & amp; & amp; intrigger == true)
{
WaspUSHED = TRUE;
}
}
Void Ontriggerstay (Collider Other)
{
Intrigger = True // You can also put on the ontriggerenter, I think the role is not playing strongly.
If (WaspUSHED == TRUE)
{
Loot ();
waspushed = false;
}
}
Void OntriggereExit (Collider Other)
{
intrigger = false;
}
It turns out that in the update when you press the button – the BOOL changes on true and in the trigger (when the character in it) is checked if the Bool True is if my loot () method is processed, and the BOOL variable becomes FALSE. Somehow, I think there is still a solution, but this is the first thing that occurred to.