Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
deleted 2 characters in body
Source Link

I have a coroutine, which I called from the Update() method on every click.

First, I call AddTrunk() to add to my trunkList, beforethen I use my coroutine to move the animation for 0.3 seconds. After 0.3 seconds, it calls Destroy(), and then it changes transform.position. However, before completing the animation, it runs transform.position; it first my tree down first, and then does the animation.


This is where I call my coroutine:

void Update () 
{
    if (Input.GetMouseButtonDown (0)) 
    {
        AddTrunk ();

        if (!isRunning) 
        {
            StartCoroutine (BranchOutAnimation ());
        }
    }
}

Here is the coroutine BranchOutAnimation():

IEnumerator BranchOutAnimation()
{
    while (true) 
    {
        isRunning = true;
        iTween.MoveTo (trunkList[index], 
            new Vector3 (trunkList[index].transform.position.x 
            - 5f, trunkList[index].transform.position.y, 
            trunkList [index].transform.position.z), 0.3f);
        yield return new WaitForSeconds (0.3f);

        Destroy (trunkList [index]);
        trunkList.RemoveAt (index);
        transform.position = new Vector3 (transform.position.x, transform.position.y 
            - treeHeight, transform.position.z);
        isRunning = false;
        yield break;
    }
}

What am I doing wrong?

I have a coroutine, which I called from the Update() method on every click.

First, I call AddTrunk() to add to my trunkList, before I use my coroutine to move the animation for 0.3 seconds. After 0.3 seconds, it calls Destroy(), and then it changes transform.position. However, before completing the animation, it runs transform.position; it first my tree down first, and then does the animation.


This is where I call my coroutine:

void Update () 
{
    if (Input.GetMouseButtonDown (0)) 
    {
        AddTrunk ();

        if (!isRunning) 
        {
            StartCoroutine (BranchOutAnimation ());
        }
    }
}

Here is the coroutine BranchOutAnimation():

IEnumerator BranchOutAnimation()
{
    while (true) 
    {
        isRunning = true;
        iTween.MoveTo (trunkList[index], 
            new Vector3 (trunkList[index].transform.position.x 
            - 5f, trunkList[index].transform.position.y, 
            trunkList [index].transform.position.z), 0.3f);
        yield return new WaitForSeconds (0.3f);

        Destroy (trunkList [index]);
        trunkList.RemoveAt (index);
        transform.position = new Vector3 (transform.position.x, transform.position.y 
            - treeHeight, transform.position.z);
        isRunning = false;
        yield break;
    }
}

What am I doing wrong?

I have a coroutine, which I called from the Update() method on every click.

First, I call AddTrunk() to add to my trunkList, then I use my coroutine to move the animation for 0.3 seconds. After 0.3 seconds, it calls Destroy(), and then it changes transform.position. However, before completing the animation, it runs transform.position; it first my tree down first, and then does the animation.


This is where I call my coroutine:

void Update () 
{
    if (Input.GetMouseButtonDown (0)) 
    {
        AddTrunk ();

        if (!isRunning) 
        {
            StartCoroutine (BranchOutAnimation ());
        }
    }
}

Here is the coroutine BranchOutAnimation():

IEnumerator BranchOutAnimation()
{
    while (true) 
    {
        isRunning = true;
        iTween.MoveTo (trunkList[index], 
            new Vector3 (trunkList[index].transform.position.x 
            - 5f, trunkList[index].transform.position.y, 
            trunkList [index].transform.position.z), 0.3f);
        yield return new WaitForSeconds (0.3f);

        Destroy (trunkList [index]);
        trunkList.RemoveAt (index);
        transform.position = new Vector3 (transform.position.x, transform.position.y 
            - treeHeight, transform.position.z);
        isRunning = false;
        yield break;
    }
}

What am I doing wrong?

clarifications as per comments
Source Link
Gnemlock
  • 5.3k
  • 5
  • 28
  • 59

I have a coroutine, which I called from the Update() method on every click.

First, I call AddTrunk() to add to my trunkList, before I use my coroutine to move anthe animation for 0.3 seconds. After 0.3 seconds, it calls Destroy(), and then it changes transform.position. However, before completing the animation, it runs transform.position; it first my tree down first, and then does the animation.


This is where I call my coroutine:

void Update () 
{
    if (Input.GetMouseButtonDown (0)) 
    {
        AddTrunk ();

        if (!isRunning) 
        {
            StartCoroutine (BranchOutAnimation ());
        }
    }
}

Here is the coroutine BranchOutAnimation():

IEnumerator BranchOutAnimation()
{
    while (true) 
    {
        isRunning = true;
        iTween.MoveTo (trunkList[index], 
            new Vector3 (trunkList[index].transform.position.x 
            - 5f, trunkList[index].transform.position.y, 
            trunkList [index].transform.position.z), 0.3f);
        yield return new WaitForSeconds (0.3f);

        Destroy (trunkList [index]);
        trunkList.RemoveAt (index);
        transform.position = new Vector3 (transform.position.x, transform.position.y 
            - treeHeight, transform.position.z);
        isRunning = false;
        yield break;
    }
}

What am I doing wrong?

I have a coroutine, which I called from the Update() method on every click.

First, I call AddTrunk() to move an animation for 0.3 seconds. After 0.3 seconds, it calls Destroy(), and then it changes transform.position. However, before completing the animation, it runs transform.position; it first my tree down first, and then does the animation.


This is where I call my coroutine:

void Update () 
{
    if (Input.GetMouseButtonDown (0)) 
    {
        AddTrunk ();

        if (!isRunning) 
        {
            StartCoroutine (BranchOutAnimation ());
        }
    }
}

Here is the coroutine BranchOutAnimation():

IEnumerator BranchOutAnimation()
{
    while (true) 
    {
        isRunning = true;
        iTween.MoveTo (trunkList[index], 
            new Vector3 (trunkList[index].transform.position.x 
            - 5f, trunkList[index].transform.position.y, 
            trunkList [index].transform.position.z), 0.3f);
        yield return new WaitForSeconds (0.3f);

        Destroy (trunkList [index]);
        trunkList.RemoveAt (index);
        transform.position = new Vector3 (transform.position.x, transform.position.y 
            - treeHeight, transform.position.z);
        isRunning = false;
        yield break;
    }
}

What am I doing wrong?

I have a coroutine, which I called from the Update() method on every click.

First, I call AddTrunk() to add to my trunkList, before I use my coroutine to move the animation for 0.3 seconds. After 0.3 seconds, it calls Destroy(), and then it changes transform.position. However, before completing the animation, it runs transform.position; it first my tree down first, and then does the animation.


This is where I call my coroutine:

void Update () 
{
    if (Input.GetMouseButtonDown (0)) 
    {
        AddTrunk ();

        if (!isRunning) 
        {
            StartCoroutine (BranchOutAnimation ());
        }
    }
}

Here is the coroutine BranchOutAnimation():

IEnumerator BranchOutAnimation()
{
    while (true) 
    {
        isRunning = true;
        iTween.MoveTo (trunkList[index], 
            new Vector3 (trunkList[index].transform.position.x 
            - 5f, trunkList[index].transform.position.y, 
            trunkList [index].transform.position.z), 0.3f);
        yield return new WaitForSeconds (0.3f);

        Destroy (trunkList [index]);
        trunkList.RemoveAt (index);
        transform.position = new Vector3 (transform.position.x, transform.position.y 
            - treeHeight, transform.position.z);
        isRunning = false;
        yield break;
    }
}

What am I doing wrong?

corrected transform.animation to transform.position
Source Link

I have a coroutine, which I called from the Update() method on every click.

First, I call AddTrunk() to move an animation for 0.3 seconds. After 0.3 seconds, it calls Destroy(), and then it changes transform.position. However, before completing the animation, it runs transform.animationposition; it first my tree down first, and then does the animation.


This is where I call my coroutine:

void Update () 
{
    if (Input.GetMouseButtonDown (0)) 
    {
        AddTrunk ();

        if (!isRunning) 
        {
            StartCoroutine (BranchOutAnimation ());
        }
    }
}

Here is the coroutine BranchOutAnimation():

IEnumerator BranchOutAnimation()
{
    while (true) 
    {
        isRunning = true;
        iTween.MoveTo (trunkList[index], 
            new Vector3 (trunkList[index].transform.position.x 
            - 5f, trunkList[index].transform.position.y, 
            trunkList [index].transform.position.z), 0.3f);
        yield return new WaitForSeconds (0.3f);

        Destroy (trunkList [index]);
        trunkList.RemoveAt (index);
        transform.position = new Vector3 (transform.position.x, transform.position.y 
            - treeHeight, transform.position.z);
        isRunning = false;
        yield break;
    }
}

What am I doing wrong?

I have a coroutine, which I called from the Update() method on every click.

First, I call AddTrunk() to move an animation for 0.3 seconds. After 0.3 seconds, it calls Destroy(), and then it changes transform.position. However, before completing the animation, it runs transform.animation; it first my tree down first, and then does the animation.


This is where I call my coroutine:

void Update () 
{
    if (Input.GetMouseButtonDown (0)) 
    {
        AddTrunk ();

        if (!isRunning) 
        {
            StartCoroutine (BranchOutAnimation ());
        }
    }
}

Here is the coroutine BranchOutAnimation():

IEnumerator BranchOutAnimation()
{
    while (true) 
    {
        isRunning = true;
        iTween.MoveTo (trunkList[index], 
            new Vector3 (trunkList[index].transform.position.x 
            - 5f, trunkList[index].transform.position.y, 
            trunkList [index].transform.position.z), 0.3f);
        yield return new WaitForSeconds (0.3f);

        Destroy (trunkList [index]);
        trunkList.RemoveAt (index);
        transform.position = new Vector3 (transform.position.x, transform.position.y 
            - treeHeight, transform.position.z);
        isRunning = false;
        yield break;
    }
}

What am I doing wrong?

I have a coroutine, which I called from the Update() method on every click.

First, I call AddTrunk() to move an animation for 0.3 seconds. After 0.3 seconds, it calls Destroy(), and then it changes transform.position. However, before completing the animation, it runs transform.position; it first my tree down first, and then does the animation.


This is where I call my coroutine:

void Update () 
{
    if (Input.GetMouseButtonDown (0)) 
    {
        AddTrunk ();

        if (!isRunning) 
        {
            StartCoroutine (BranchOutAnimation ());
        }
    }
}

Here is the coroutine BranchOutAnimation():

IEnumerator BranchOutAnimation()
{
    while (true) 
    {
        isRunning = true;
        iTween.MoveTo (trunkList[index], 
            new Vector3 (trunkList[index].transform.position.x 
            - 5f, trunkList[index].transform.position.y, 
            trunkList [index].transform.position.z), 0.3f);
        yield return new WaitForSeconds (0.3f);

        Destroy (trunkList [index]);
        trunkList.RemoveAt (index);
        transform.position = new Vector3 (transform.position.x, transform.position.y 
            - treeHeight, transform.position.z);
        isRunning = false;
        yield break;
    }
}

What am I doing wrong?

formatting; grammar and punctuation
Source Link
Gnemlock
  • 5.3k
  • 5
  • 28
  • 59
Loading
Source Link
Loading