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 /
  • Help Room /
avatar image
0
Question by BaronWhite · Mar 24, 2018 at 01:21 PM · instantiatescriptableobjectdelayskills

Scriptableobject delay for AoE skill which instantiates multiple objects;

Hello, I'm making some SO skills , however I have a AoE one which I need to instantiate cannonballs in random circle over time. When they start there's a cannon sound and then that high pitched falling sound followed by an explosion sfx/vfx on collision. Like Gangplank's ult in LoL if anyone plays, here's an example ( https://youtu.be/IpTFhJApRUg?t=1m21s )

The problem is exactly how do I cause a delay on the instantiate...

 public override void (Trigger()
 {
     for (int i = 1; i < iterations + 1; i++)
     {
         //Invoke("InstantiateCannonball", 0.5f * i);
     }
 }

 void InstantiateCannonball()
 {
     GameObject cb = Instantiate(cannonball, new Vector3(
             caster.transform.position.x + Random.Range(-2f, 2f),
             caster.transform.position.y + 4,
             caster.transform.position.z + Random.Range(-2f, 2f)), Quaternion.identity) as GameObject;
 }

I thought I might use Invoke, but it derives from Mono after all. Now I had the idea of maybe starting a coroutine in the script that manages and calls the skills like so, haven't tested it yet as I need to figure out which skill would need to be called. Any ideas anyone? Thanks.

 IEnumerator CallRepeatedely(string function, float delay, float times)
 {
     WaitForSeconds wfs = new WaitForSeconds(delay);
     for (int i = 0; i < times; i++)
     {
         Invoke(function, 0);
         yield return wfs;
     }
 }


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 BaronWhite · Mar 24, 2018 at 03:23 PM

Hello, I figured a workaround for this one.

I set the cannonball as kinematic at first and the set the delay parameters.

In the skill SO

 for (int i = 1; i < iterations + 1; i++)
         {
             CannonBall cb = Instantiate(cannonball, new Vector3(
                 caster.transform.position.x + Random.Range(-2f, 2f),
                 caster.transform.position.y + 4,
                 caster.transform.position.z + Random.Range(-2f, 2f)), Quaternion.identity).GetComponent<CannonBall>();
 
             // Set up the cannonball;
             cb.Set(i/2, damage, cannonSFX, fallSFX, explosionSFX, explosionVFX);
             
             //   InstantiateCannonball(i / 2);
         }


Then in the cannonball monobehaviour: The reason for the reaaaally long parameters is that I think putting everything on the cannonball would defeat the purpose of having a scriptable object skill, that way the special effect references are all in the SO and not in the prefab, which could be interchanged. Speaking of which maybe I should add some code to detect whether the prefab has a Rigidbody and CannonBall script as well.

 public void Set(float delay, float dmg, VariableVolumePitch cannonSfx, VariableVolumePitch fallSfx, VariableVolumePitch explosionSfx, GameObject explosionVfx)
     {
         damage = dmg;
 
         // Sound effects.
         cannonSFX = cannonSfx;
         fallSFX = fallSfx;
         explosionSFX = explosionSfx;
 
         // Visual effects.
         explosionVFX = explosionVfx;
 
         Invoke("Fire", delay);
     }
 
     public void Fire()
     {
         cannonSFX.Play(GetComponent<AudioSource>());
         Invoke("Fall", 1);
     }
 
     public void Fall()
     {
         fallSFX.Play(GetComponent<AudioSource>());
         GetComponent<Rigidbody>().isKinematic = false;
     }
 
     private void OnCollisionEnter(Collision collision)
     {
         (...)
     }
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

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

Related Questions

Instantiating a GameObject from a ScriptableObject 1 Answer

Can't drag objects into button prefabs to enable OnClick() 0 Answers

C# Add Unique Listener to Buttons Instantiated from List 0 Answers

Instaniate delay issue 0 Answers

When instantiating 3 clones are created rather then 1 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