What I want to achieve is to activate a shield with colliders or triggers, with the left mouse button "Fire 2" when a rocket hits me and does not destroy me.
What I want to achieve is to activate a shield with colliders or triggers, with the left mouse button "Fire 2" when a rocket hits me and does not destroy me.
What if while the secondary click is pressed, you deflect the damage dealt? that is, when the rocket hits the player, it generates damage, which is directly related to the player's life, if the player has the secondary click pressed, this damage is no longer related to the player's life, and simply does the action of exploding, I don't have unity installed at the moment so I can only help you with theory :)
Assuming that the rocket launches correctly, that it is a rigidbody that you give it a boost to, and that the shield is an object that is referenced from the Inspector panel, the class approach
quitarshieldlollevaelescudo
seems correct to me, but I see some errors that will prevent you from executing the code. To begin with, you have a public field calledescudo
, but then you apparently refer to it by nameshield
. Also, you are missing a parenthesis in that if statement.Now, you should add a script to the shield and implement the method
OnCollisionEnter()
to destroy the rocket every time it collides with it. Add a "missile" tag to the rocket prefab and do something like this: