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 sam32x · Jan 25, 2013 at 01:16 AM · bulletinvokesomething

script doesn't do anything

i made a script but nothing happens, i might have just made some simple mistake because i havent used unity in about 4 months

 var health = 999;
 var bullet1 : GameObject;
 var bullet2 : GameObject;
 var player : Transform;
 
 function Start () {
 Invoke("Shoot",3);
 }
 
 function OnCollisionEnter () {
 health -= 1;
 }
 
 function Shoot () {
 if(health >= 800){
 if(health <= 1000){
 transform.LookAt(player);
 Instantiate(bullet1,transform.position,transform.rotation);
 yield WaitForSeconds(0.01);
 Instantiate(bullet2,transform.position,transform.rotation);
 yield WaitForSeconds(0.02);
 Instantiate(bullet1,transform.position,transform.rotation);
 yield WaitForSeconds(0.04);
 Instantiate(bullet2,transform.position,transform.rotation);
 yield WaitForSeconds(0.08);
 Instantiate(bullet1,transform.position,transform.rotation);
 yield WaitForSeconds(0.16);
 Instantiate(bullet2,transform.position,transform.rotation);
 yield WaitForSeconds(0.24);
 Instantiate(bullet1,transform.position,transform.rotation);
 yield WaitForSeconds(0.32);
 Instantiate(bullet2,transform.position,transform.rotation);
 Invoke("Shoot",0.5);
 }
 }
 }

what i want to do is shoot a stream of bullets at the player but no bullets appear, there are no error messages and the bullets and player are assigned to the object correctly

Comment
Add comment · Show 6
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 cdrandin · Jan 25, 2013 at 01:26 AM 0
Share

I am confused. This looks like a weapon controller yet it has health on it? Anyway, check your bullet gameobject. Also you are delaying the bullet creation in tiny incremental amount. You could use a for loop to do the same thing. Also, Invoke calls the function after x seconds. First try to instantiate one at a time.

Also make sure it is attached to a game object.

avatar image sam32x · Jan 25, 2013 at 02:05 AM 0
Share

i wanted to have it like that so that when the enemy was between 800 and 600 health i would make a different sequence

ill see if changing shoot to start makes it shoot

avatar image cdrandin · Jan 25, 2013 at 02:34 AM 0
Share

you could use state machine like normal, angry, frenzy type modes which are seen in a couple of games, but I digress. Anyway, just check if it is the game object not being created or the script. Also, if you even have it attached to an object, sometimes we miss it and check if it is enabled as well.

avatar image sam32x · Jan 25, 2013 at 02:50 AM 0
Share

i changed function shoot to function start and it shot once, also i updated to unity 4 and now i get an error message with a white speech bubble thing telling me that the function shoot couldn't be called

yes i googled it

avatar image sam32x · Jan 25, 2013 at 02:55 AM 0
Share

its attached and enabled

Show more comments

1 Reply

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

Answer by sam32x · Jan 25, 2013 at 03:25 AM

i removed the waitforseconds thing because that was the only thing there that i hadn't used before and it started working but then it stopped again for no reason.

here is my script now

 var health = 5000;
 var bullet1 : GameObject;
 var bullet2 : GameObject;
 var bullet1f : GameObject;
 var bullet2f : GameObject;
 var player : Transform;
 
 function Start () {
 Invoke("Shoot",3);
 }
 
 function OnTriggerEnter () {
 health -= 1;
 }
 
 function Shoot () {
 if(health >= 5000){
 if(health <= 4750){
 transform.LookAt(player);
 Instantiate(bullet1,transform.position,transform.rotation);
 Instantiate(bullet2,transform.position,transform.rotation);
 Invoke("Shoot",0.5);
 }
 }
 if(health >= 4750){
 if(health <= 4500){
 transform.LookAt(player);
 Instantiate(bullet1f,transform.position,transform.rotation);
 Instantiate(bullet2f,transform.position,transform.rotation);
 Invoke("Shoot",0.5);
 }
 }
 if(health >= 4500){
 if(health <= 4250){
 transform.LookAt(player);
 transform.Rotate(Vector3.left * 30);
 Instantiate(bullet1,transform.position,transform.rotation);
 transform.Rotate(Vector3.right * 15);
 Instantiate(bullet1,transform.position,transform.rotation);
 transform.Rotate(Vector3.right * 15);
 Instantiate(bullet1,transform.position,transform.rotation);
 transform.Rotate(Vector3.right * 15);
 Instantiate(bullet1,transform.position,transform.rotation);
 transform.Rotate(Vector3.right * 15);
 Instantiate(bullet1,transform.position,transform.rotation);
 transform.Rotate(Vector3.left * 30);
 Invoke("Shoot",0.5);
 }
 }
 }
Comment
Add comment · Show 9 · 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 cdrandin · Jan 25, 2013 at 03:29 AM 0
Share

Something is telling me that maybe there is a problem with Invoking a function in itself, but not completely sure.

avatar image cdrandin · Jan 25, 2013 at 03:32 AM 0
Share

After googling some stuff I came across http://answers.unity3d.com/questions/376748/invokerepeating-stops-suddenly.html

Check out http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.InvokeRepeating.html see if that helps.

avatar image sam32x · Jan 25, 2013 at 03:57 AM 0
Share

InvokeRepeating didn't work and neither did changing Invoke("Shoot",3); to Shoot();

avatar image cdrandin · Jan 25, 2013 at 04:06 AM 0
Share

Could you post the code, because the one just above says you are still using Invoke.

avatar image sam32x · Jan 25, 2013 at 04:16 AM 0
Share
 var health = 5000;
 var bullet1 : GameObject;
 var bullet2 : GameObject;
 var bullet1f : GameObject;
 var bullet2f : GameObject;
 var player : Transform;
 
 function Start () {
 Shoot();
 }
 
 function OnTriggerEnter () {
 health -= 1;
 }
 
 function Shoot () {
 if(health >= 5000){
 if(health <= 4750){
 transform.LookAt(player);
 Instantiate(bullet1,transform.position,transform.rotation);
 Instantiate(bullet2,transform.position,transform.rotation);
 Invoke("Shoot",0.5);
 }
 }
 if(health >= 4750){
 if(health <= 4500){
 transform.LookAt(player);
 Instantiate(bullet1f,transform.position,transform.rotation);
 Instantiate(bullet2f,transform.position,transform.rotation);
 Invoke("Shoot",0.5);
 }
 }
 if(health >= 4500){
 if(health <= 4250){
 transform.LookAt(player);
 transform.Rotate(Vector3.left * 30);
 Instantiate(bullet1,transform.position,transform.rotation);
 transform.Rotate(Vector3.right * 15);
 Instantiate(bullet1,transform.position,transform.rotation);
 transform.Rotate(Vector3.right * 15);
 Instantiate(bullet1,transform.position,transform.rotation);
 transform.Rotate(Vector3.right * 15);
 Instantiate(bullet1,transform.position,transform.rotation);
 transform.Rotate(Vector3.right * 15);
 Instantiate(bullet1,transform.position,transform.rotation);
 transform.Rotate(Vector3.left * 30);
 Invoke("Shoot",0.5);
 }
 }
 }
Show more comments

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

9 People are following this question.

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

Related Questions

Invoke not working from Start() ? 1 Answer

how to make it so i can see a raycast 2 Answers

Control amount of bullets 2 Answers

Invoke is not working properly. 0 Answers

simple Shooting in C# script please 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