Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by RaiderA528 · Sep 26, 2011 at 06:59 PM · instantiateprojectiledamagefiringhealth

Instantiate a projectile on key press "F" key / OnMouseDown! Help!!!

Okay so again I'm stuck, I want a prefab of a sphere that emits which I have created to get fired/(instantiated) out from the player_character I have when either I click the "left mouse button" or hit the "F" key. The Sphere is tagged as "PlayerProjectile". I'm assuming it'd be something on the function Update like function Update() { if(Input.GetAxis("Fire1") >.1) { instantiate."player projectile"; } } I know that's the wrong way it'd be written I just need a little help. Thanks!!! Also if anyone could throw it I have an enemy cube with a health GUI display and a health variable and i need a way in that enemy's health script to detect if its been hit by one of these PlayerProjectiles and lose health accordingly. The Script on the Enemy Cube is - var hp:float; var maxhp:float; var healthbarWidth:int; var myHealthbar:GameObject; var myhb:GameObject;

function Start(){ healthbarWidth=20; myhb=Instantiate(myHealthbar,transform.position,transform.rotation); }

function Update(){

 myhb.transform.position=Camera.main.WorldToViewportPoint (transform.position);
 myhb.transform.position.x-=.05;
 myhb.transform.position.y-=.05;
 myhb.transform.localScale=Vector3.zero;
 var healthpercent:float=hp/maxhp;
 if(healthpercent<0){healthpercent=0;}
 if(healthpercent>100){healthpercent=100;}
 healthbarWidth=healthpercent*20;
 myhb.guiTexture.pixelInset=Rect(20,20,healthbarWidth,10);

} Of course that part won't do me any good until i can actually fire the projectiles. Thanks for any help in advance. : )

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Piflik · Sep 26, 2011 at 07:49 PM

 if(Input.GetKeyDown(KeyCode.F) || Input.GetKeyDown(KeyCode.Mouse0))
     Instantiate(Prefab, transform.position, Quaternion.identity);

Format your code correctly next time, please. It is hard to read as it is now.

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
avatar image
0

Answer by RaiderA528 · Oct 04, 2011 at 01:10 PM

Sorry it messed up when I posted it. it was indented and everything in the text box when i typed it in! : s

Comment
Add comment · Show 1 · 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
avatar image BiG · Oct 04, 2011 at 02:51 PM 0
Share

Also select @Piflik's answer as the correct one, if he helped you! :) The question will be marked as "solved" in this way.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Firing only a single projectile at a time, then adding a second. 2 Answers

Prefab shooting damage/health? 1 Answer

how to take health/hearth from player when colliding with an object? 2 Answers

Enemy Health Damage 2 Answers

How to create an NPC enemy which can take damage and be killed when its energy or health reaches zero? 2 Answers


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