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 Stef · Jul 19, 2014 at 04:09 PM · instancestopcancel

Stop instance

Lads,

I'm trying to cancel an instantiation. Currently the invoke continues to instance the gameobject after 'towerdamage' == 0. Here's my script:

 using UnityEngine;
 using System.Collections;
 
 public class Strike_Details : MonoBehaviour {
 
 
         
         public float strikeSpeed = 1f;
         Tower_Damage script;
         
         void Start()
         {
             Invoke ("SpawnObject", strikeSpeed);
             script = gameObject.GetComponent<Tower_Damage>();
         }
         
         void SpawnObject()
         {
             Instantiate(gameObject, transform.position, transform.rotation);
             Destroy (gameObject);
         }
         void update ()
         {
         if (script.towerDamage == 0)CancelInvoke (gameObject);
         }
     }

Any ideas?

Stef

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 gjf · Jul 19, 2014 at 04:42 PM

CancelInvoke() needs to have the method name passed to it, not the gameObject

see here

Comment
Add comment · Show 5 · 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 Stef · Jul 19, 2014 at 04:48 PM 0
Share

So in the above example, what would the method name be?

avatar image gjf · Jul 19, 2014 at 05:00 PM 0
Share

same as when you invoked it:

 Invoke ("SpawnObject", strikeSpeed);

so you'd do

 CancelInvoke("SpawnObject");

avatar image Stef · Jul 19, 2014 at 05:06 PM 0
Share

Tried it... doesn't seem to work. For some reason the objects continue to spawn, ugh.

avatar image Stef · Jul 19, 2014 at 05:25 PM 0
Share

Actually, the problem might be co$$anonymous$$g from another script that is associated with the same instance:

 public class Strike_Tower : $$anonymous$$onoBehaviour 
 {
 
     public Transform strikePrefab;
     public GameObject towerDamageScript;
 
     private Animator animator;
     private Tower_Damage playerScript;
         
 
     void Start()
     
     {
         animator = GetComponent<Animator>();
         playerScript = towerDamageScript.GetComponent<Tower_Damage>();
             }
     
     void OnTriggerEnter(Collider col) 
     {
         if(col.gameObject.tag == "Tower")
         {
             animator.SetBool("Hit", true);
             Instantiate (strikePrefab, transform.position, transform.rotation);
         }
         if (playerScript.towerDamage == 0)
         {
             animator.SetBool("Hit", false);
             animator.SetBool("Stalk", true);
             CancelInvoke (Instantiate);
         }
         
     }
 
 }

...so how do i cancel the invoke here, because what im trying in this script isn't working either... thanks for the help.

avatar image gjf · Jul 20, 2014 at 10:09 AM 0
Share

that's not even going to compile. there is no invoke.

what are you trying to cancel? CancelInvoke() only works when you've used Invoke/InvokeRepeating() to, err, invoke something.

do you want the towerDamage test to happen for any object which has collided or just those tagged with "Tower"?

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

22 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

Related Questions

How do I keep an increment process continuous without the update function? 2 Answers

Any way to stop a build? 3 Answers

Cancel WWW post operation 1 Answer

I need help with the location of instatiated objects on the scene and correct interaction with this 2 Answers

Sound stops when object is destroyed 6 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