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
0
Question by RickHurd · Apr 14, 2013 at 01:27 AM · enemyparticlesystemturret

Turret won't shoot

I have a turret that looks at the player and is supposed to shoot a ParticleSystem at the player. It looks at the player just fine, but even out of the safe distance I have setup it will not trigger the ParticleSystem. Here is my script:

 var findTarget : Transform ;
 var lookAtDistance = 20; 
 var safeDistance = 15; 
 var fireDelay : float;
 var prefab : ParticleSystem;
  
 function Update(){
  
    var distanceToPlayer = Vector3.Distance(this.transform.position, findTarget .transform.position);
  
    transform.LookAt(findTarget);
  
    if( Input.GetKeyDown( KeyCode.Space ) ) {
       Fire(); 
    }
 }     
  
 function Fire() {
    Debug.Log("Fire away!");  
    var clone : ParticleSystem;
  
    clone = Instantiate(prefab, transform.position, transform.rotation) as ParticleSystem;
 }    

I also need some help adding the ability to take away health points upon contact with the ParticleSystem and player. I'm focusing on the shooting aspect for now but I will need to take damage when that is all ready and done.

Comment
Add comment · Show 16
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 Chronos-L · Apr 14, 2013 at 01:54 AM 0
Share
 //Change this
 if( Input.Get$$anonymous$$eyDown( $$anonymous$$eyCode.Space ) ) {
    Fire(); 
 }
 
 //To this
 if( distanceToPlayer <= safeDistance ) {
    Fire(); 
 }

In your previous question, I put in the Input.Get$$anonymous$$eyDown( $$anonymous$$eyCode.Space ) for quick-debugging purposes by skipping the check distance.

avatar image Negagames · Apr 14, 2013 at 02:43 AM 0
Share

On top of what Chronos-L said, is your prefab object containing a rigidbody?

avatar image RickHurd · Apr 14, 2013 at 04:43 AM 0
Share

the prefab is a particle system, can you make particle systems have rigidbody?

after changing it back to

if( distanceToPlayer <= safeDistance ) { Fire(); }

the particle system still does not fire.

avatar image Chronos-L · Apr 14, 2013 at 05:24 AM 0
Share

Do you have the "Fire away!" message in your console? Or do you have any error messages?

avatar image RickHurd · Apr 15, 2013 at 02:58 AM 1
Share

ahhh it works !!! lol ok cool thanks Chonos i'll go from here

btw if you convert that last comment into a answer i'll call it a day for this Question :D thanks for all your help

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Chronos-L · Apr 15, 2013 at 12:38 AM

This is the one that works in my PC. There are no major difference with yours except that mine is a stripped down version. You can give this a shot.

 #pragma strict
 
 var prefab : ParticleSystem;
  
 function Update(){     
    if( Input.GetKeyDown( KeyCode.Space ) ) {
       Fire(); 
    }
 }     
  
 function Fire() {
    Debug.Log("Fire away!");  
    var clone : ParticleSystem;     
    clone = Instantiate(prefab, transform.position, transform.rotation) as ParticleSystem;
 }  
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

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

making an enemy bullet ignore other enemies 1 Answer

turret having a range of tiles 0 Answers

Detection Perimiter 3 Answers

Two Questions... How to make a tracking turret, how to have enemies home in towards the player's positions 2 Answers

Turrent detection issue. 0 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