Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 PancakesNBacon · Jul 04, 2015 at 05:16 AM · spawndelayfireball

Classic Fireball Shooting Up Obstacle

I am trying to make a "fireball" (in this case water) spawn every 3 seconds, shoot straight up, and fall back down. Like the classic fireball obstacle in old Mario games.

With the code I have so far, it just sends the waterball straight up and it never comes back down. Also, another one does not spawn after 3 seconds. Coding is not my thing so if anyone could help that would be great.

 using UnityEngine;
 using System.Collections;
 
 public class waterBall : MonoBehaviour {
 
     public float shotDelay = 3f;
     public Projectile projectile;
 
     private float shotHeight = 20;
 
     // Use this for initialization
     void Start () {
         if (shotDelay > 0) {
             StartCoroutine(OnFire());
         }
     }
     
     // Update is called once per frame
     void Update () {
         if (projectile) {
             Projectile clone = Instantiate(projectile,transform.position, Quaternion.identity) as Projectile;
         }
         GetComponent<Rigidbody2D>().AddForce(new Vector2(0, shotHeight));
     }
 
     IEnumerator OnFire(){
         yield return new WaitForSeconds(shotDelay);
         StartCoroutine(OnFire());
     }
 
 }
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 Tomer-Barkan · Jul 04, 2015 at 05:22 AM

  1. You check "projectile" before deciding whether to instantiate or not. I assume you want to create a new one when the first one is destroyed?

  2. You add force to the projectile every frame (in the update). Instead just set the velocity to the starting velocity you want, but only once when instantiating, not every frame.

  3. You need to add code to projectile that will destroy it after it finishes falling or the new one won't be created ever.

  4. Make sure your projectile is affected by gravity.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to Instantiate prefabs with function Update? 1 Answer

Delaying in for loop, Spawning enemies 1 Answer

delay first spawn 2 Answers

How do I put a delay in this script ? 1 Answer

WaitForSeconds Not Working 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