|
How can i shoot whith the space bar. I am making a 3rd person and i want my character to shoot fire out of its mouth. I made a script from a tuorial and it wont work.Can anyone help me by putting up a script.
(comments are locked)
|
|
Alright, it would help if you posted up your script. You really shouldn't ask people to write scripts for you, or even put them up for you. The is to help with your problem, not give you code. What Cristian Stewart said was correct, but obviously that's not the whole thing. This will probably be the only time someone will help you by giving you a script, but I'm going to explain things to you: First, use the default code that's already set up: The Update function is called twice a frame. Next we have to add the variables that you would need: "fireBall" needs to be a GameObject. "shootPoint" needs to be a transform because that's where the fireBall is going to come out. If you want it to come out of his mouth, put an empty gameObject near his mouth. Make sure the shootPoint is a child of the object that has the script. Now for the actual code that makes it happen: The first line of code, the "if" statement, means that whatever below will only be executed if anything in the if statement is met. The The completed line is above. Next, we want it to shoot if they click, OR if they hit "space". To do that we need to put in the rest of the if statement: To make sure it means OR, we need these symbols To keep the script organized, and to make sure the if statement doesn't mess with any other code, we put in brackets: Now the conditions are set we need it to actually DO something. For that we INSTANTIATE something. Instantiate means "create" after we write Instantiate, we need to write what's instantiate, and how it's going to be displayed. So the first part inside the parenthesis is what's going to be instantiated, in this case, the fireBall: Next, we need to display where it's going to be shot from. Normally, it's written like this: With that, it will be shot from the center of the object it's attached to. But to make it come from a specific place we write it like this: Now we need to make sure it's rotation is displayed too: With the above code, the fireball will have no rotation, which is fine. So that's how it works. I really hoped this helped. The completed script is this:
(comments are locked)
|
|
this clears a lot thx nighthawx Your welcome. And also, put comments like this under comments, not answers because it's not an answer.
Oct 04 '11 at 03:43 AM
Overlord
(comments are locked)
|
|
Yes, this is easy. Here's a simple shoot script. I assume the one your using uses something like the following
What you want to do to enable spacebar is this -
you see? The || means "or" - so if either of them are pushed it will fire. The space part will allow it to trigger when you hit space. Keep looking at the tutorials etc to get started, Christian Stewart It's recommended to not use GetKeyDown and instead us the Input Manager so that keys can be rebound on the user side. See documentation here: http://unity3d.com/support/documentation/Manual/Input.html
Jun 07 '10 at 02:47 AM
Tetrad
(comments are locked)
|
|
If you want your character to breathe fire, this is probably the best way. Make a particle emitter and place it where in the mouth you want the fire to come from. Assign the particle material to fire (built into unity) and set the force, animation, etc properties as you wish. In order to make the emitter emit when the player is pressing down the spacebar, you would use this: WhateverYouCalledYourParticleEmitter.emit = false funtion Update() { if(Input.GetButton("Jump")) { WhateverYouCalledYourParticleEmitter.emit = true } } Hope I was of help to ya :) ~Choco i tried your scirpt i get errors regarding semicolons and other stuff.....could you write your code again or soemthing
Oct 03 '11 at 11:59 PM
rohan bhangui
(comments are locked)
|
