- Home /
fps shooting enemy
I have been using Unity for about 2 weeks now and after brief knowledgeI am trying to make an FPS game and it requires only shooting. The way i want to approach is as follows:
The camera has a raycast and has the crosshair GUI texture at the centre thus the gun does not have any bullets it only animates when the mouse is clicked.
When the raycast hits a gameobject tagged "enemy" the crosshair changes to red
And if the mouse is clicked at the same moment then i want the player to animate according to the organ that is hit . Example if it hits the head the health directly goes to zero and animation plays.
The third step is doubtful . I was thinking that when mouse is clicked then the name of the organ colliding with the ray is stored as a string this maybe can be done by keeping different name for chest, head, arms, legs etc.
Then its passed on to a Javascript associated with the enemy and it checks: if the string is "leftArm" then it plays some animation and health drops by 20% or if "rightLeg" then something else and health drops by something else.
But there is a problem that even when i am reloading the gun keeps shooting how to rectify it? Are there any other problems that i might face due to this?
Since i am new to this i have a small doubt. If i have something like this :
// i could get "leg" by the above mentioned method
if(shotOrgan = "leg"){
enemyCharactor.animation.Play("legHurt");
audio.PlayOneShot(pain scream);
health -= 20;
}
Do the animation and sound take place simultaneously or is it like first the animation occurs and then the sound plays?
Sorry for a big post..... i am very new and its my first question!
Answer by StephenLTGAMES · Mar 20, 2011 at 03:56 PM
Its a long time but i may answer in case someone else wonder on to this.
You could set up a counter so when it is a certain amount stop firing.
For example
(C# Coding)
int BulletsInGun = 40;
in your gun fire code(fired add
//EnegyInGun. (could be more appopriate if you ain;t using bullets). BulletsInGun ++;
and
if(BulletsInGun > 0 )
{
Do your gun code.
}
else
{ Do Reload code. (You can do this to allow automatic reloading) or set it to button press.
}
Your answer
Follow this Question
Related Questions
Multiplayer FPS Bullets: should they be rigid bodies or raycast? 1 Answer
shooting multiple enemies using raycast 2 Answers
Straight Raycast Shooting 1 Answer
Using raycast gun to take down life of enemy when shot 1 Answer
How to make enemy`s gun shoot directly on player and its allies from some distance. 1 Answer