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 SlyyGuyy · Mar 11, 2014 at 02:40 AM · javascriptenemyshootingshootenemyai

Clones of enemies will not shoot

Currently in my game I'm creating clones of enemies and they are supposed to be shooting with specific time variables. I am currently calling the specific name of their object and I'm telling the game to spawn projectiles in front of them as they move. I'll post the code, but they are currently not shooting at all and I was wondering what's going on? My game objects are stored in an array and so the enemy[0] is calling that specific enemy and telling it to shoot.

 var enemyProjectile : Transform;
 var shootCoolDown : float;
 var shootTimer : float; //Records how much time between shots
 
 function shootLazer() {
     shootTimer += Time.deltaTime;
     if (shootTimer < shootCoolDown) {
         return;
     }
     
     if(gameObject.name == ("Enemy_Pink(Clone)")) {
         shootCoolDown = 1.75;
         shootTimer = 0; //Reset Timer
             var pinkClone : Transform;
             var pinkProjectileOriginX = enemy[0].transform.position.x;
             var pinkProjectileOriginY = enemy[0].transform.position.y - 1;
             var pinkProjectileOriginZ = enemy[0].transform.position.z;
             
             pinkClone = Instantiate(enemyProjectile, Vector3(pinkProjectileOriginX, pinkProjectileOriginY, pinkProjectileOriginZ), transform.rotation);
             pinkClone.rigidbody.AddForce(pinkClone.transform.up * -300);
             Destroy(pinkClone.gameObject, 2);
     }
     if(gameObject.name == ("Enemy_Blue(Clone)")) {
         shootCoolDown = 1.5;
         shootTimer = 0; //Reset Timer
             var blueClone : Transform;
             var blueProjectileOriginX = enemy[1].transform.position.x;
             var blueProjectileOriginY = enemy[1].transform.position.y - 1;
             var blueProjectileOriginZ = enemy[1].transform.position.z;
             
             blueClone = Instantiate(enemyProjectile, Vector3(blueProjectileOriginX, blueProjectileOriginY, blueProjectileOriginZ), transform.rotation);
             blueClone.rigidbody.AddForce(blueClone.transform.up * -300);
             Destroy(blueClone.gameObject, 2);
     }
     if(gameObject.name == ("Enemy_Red(Clone)")) {
         shootCoolDown = 1.25;
         shootTimer = 0; //Reset Timer
             var redClone : Transform;
             var redProjectileOriginX = enemy[2].transform.position.x;
             var redProjectileOriginY = enemy[2].transform.position.y - 1;
             var redProjectileOriginZ = enemy[2].transform.position.z;
             
             redClone = Instantiate(enemyProjectile, Vector3(redProjectileOriginX, redProjectileOriginY, redProjectileOriginZ), transform.rotation);
             redClone.rigidbody.AddForce(redClone.transform.up * -300);
             Destroy(redClone.gameObject, 2);
     }    
 }
Comment
Add comment · Show 1
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 ShadoX · Mar 11, 2014 at 08:34 AM 0
Share

Any errors or warnings when the clones should shoot? Perhaps "enemyProjectile" isn't set for the clones (at last I don't see the variable ever being set in the code above unless you did it in the editor via preFabs..)

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Enemy fire does not propel in any direction? 1 Answer

Enemy AI problem 1 Answer

Enemies Shoot Towards Face, Would Like to have them Shoot to Chest 1 Answer

How to stop enemies from shooting each other 1 Answer

Make enemy more intelligent 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