- Home /
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
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
same as when you invoked it:
Invoke ("SpawnObject", strikeSpeed);
so you'd do
CancelInvoke("SpawnObject");
Tried it... doesn't seem to work. For some reason the objects continue to spawn, ugh.
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.
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
Follow this Question
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