- Home /
Make lerpz invisible to enemies by hitting fire 2? A cloak?
Hello All,
I just recently got into unity (and really dig it), but scripting is definitely my weakest point right now. There are three gameplay mechanics I'd like to add in and have no clue how to. Help on ANY of these would be stellar... thanks in advance!
1.) What I would like to do is when the player presses and holds the "fire 2" button a quick particle effect plays as a one shot, a sound effect plays as a one shot, the player model disappears so all you can see is the shadow blob, and lastly enemies ignore the player. When the player releases the fire 2 button an additional sound plays, the same particle effect plays, the player model pops back into view, and enemies can now "see" the player.
2.) I'd like to start the player off with no jumping ability... which I know is just making canjump false at first. Additionally, when the player hits the space bar a sound plays and a short spark particle emits from the jetpack to further signify it isn't working yet. When the player picks up a specific fuel cell... I want the jetpack to work as it normally does.
3.) Lastly, how would I play more than one sound for the jetpack so that an intro sound plays as a oneshot over the first part of the loop when the player presses space and an outro sound plays as the player releases space and the loop stops. I've added in audio variables to the jet pack script but can't figure out how to call them.
So, any ideas? I've been searching for any leads and have had no luck. Thanks in advance!
Answer by Jesse Anders · Apr 08, 2011 at 03:24 PM
You'll probably have better luck with each of these posted as its own question :)
Anyway, once you've learned the basics of instantiating and destroying or activating/deactivating objects, enabling/disabling components, and so on, it should become fairly clear how the things you describe can be done.
The first problem, for example, breaks down into a few different parts:
- Detecting when the button has been pressed (see the Input class and the input manager)
- Detecting when the button has been released (same)
- Instantiating or activating/enabling a particle effect (see Instantiate and look into prefabs)
- Playing a sound (see AudioSource, AudioClip, PlayOneShot(), PlayClipAtPoint(), etc.)
- Hiding and showing the player model (look into the 'enabled' property of the Renderer component; for a gradual effect, look into alpha blending)
- Having NPCs ignore the player when the player is invisible (multiple solutions, but search for 'accessing other game objects' in the scripting reference for some hints)
As you can see, there are multiple sub-problems that have to be solved here. Multiply that by your three questions, and there are about 20 different questions that need to be answered :) (Which is why one question per post might be better.)
I'm not sure which of the steps described above you need help with, but if you run into specific problems with any of them, post here or on the forums and someone will likely be able to help.
Your answer
![](https://koobas.hobune.stream/wayback/20220613121619im_/https://answers.unity.com/themes/thub/images/avi.jpg)