x


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!

more ▼

asked Dec 24 '10 at 07:25 AM

user-7688 (google) gravatar image

user-7688 (google)
11 1 1 2

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

}

more ▼

answered Mar 20 '11 at 03:56 PM

StephenLTGAMES gravatar image

StephenLTGAMES
41 2 3 5

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1535
x1175
x655
x275
x69

asked: Dec 24 '10 at 07:25 AM

Seen: 1339 times

Last Updated: Dec 24 '10 at 07:25 AM