Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by user-7688 (google) · Dec 24, 2010 at 07:25 AM · raycastfpsenemyshootingbullets

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges