Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #196 #223

Merged
merged 6 commits into from
May 15, 2016
Merged

Issue #196 #223

merged 6 commits into from
May 15, 2016

Conversation

otaconwow
Copy link
Member

Utilizar FixedUpdate() ao invés de Update().
Utilizar Coroutine.
Habilitar edição visual do ponto B.

Utilizar FixedUpdate ao invés de Update.
Utilizar Coroutine.
Habilitar edição visual do ponto B.
Remoção de variável não utilizada.
@otaconwow otaconwow changed the title Bird Issue #196 May 14, 2016
@otaconwow
Copy link
Member Author

O rename do prefab para bird será feito em outra tarefa do board muvuca iniciante:

https://trello.com/c/qeLgt12R/351-passaro-com-trajetoria-correcoes-programacao

}
IEnumerator Move()
{
for (float f = 1f; f >= 0; f -= 0.1f)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Por que esse for? Pq ele executa só 10 vezes? Como sabe que ja chegou no target pra parar de rodar o Coroutine?

Nao seria melhor um while que verifica se a distancia atual pro target é pequena, ou zero?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StefanWerW Pode ser, eu apenas mantive a lógica que havia sido implementada inicialmente. Vou fazer os testes da forma que você falou e faço a alteração. :)

Remoção do for utilizado na função Move, pois este não era necessário.
@otaconwow
Copy link
Member Author

@StefanWerW inclui mais 1 commit removendo o uso do for, pelo que vi não é necessário esse controle para controlar o movimento.

* Fix Coroutine usage

* Fix Editor

* Remote Debug
@otaconwow
Copy link
Member Author

otaconwow commented May 15, 2016

@StefanWerW pq é necessário criar a variavel de moveCoroutine? Se usarmos apenas o StartCoroutine(Move()) o resultado é o mesmo.

public class MoveAtoB : MonoBehaviour
{
[SerializeField]
private Vector3 pointA;
[SerializeField]
private Vector3 pointB = new Vector3(2, 0, 0);
[Range(0.0f, 20.0f)]
public float speed = 2f;

void Awake()
{
pointA = new Vector3(transform.position.x, transform.position.y, transform.position.z);
pointB = transform.TransformPoint(pointB);
StartCoroutine(Move());
}

private IEnumerator Move()
{
    while(Vector3.Distance(transform.position, pointB)!=0){
        float step = speed * Time.deltaTime;        
        transform.position = Vector3.MoveTowards(transform.position, pointB, step);
        yield return null;
    }
    print("Chegou ao destino");
    yield return new WaitForSeconds(3f);
    print("Coroutine finalizada");
}
}

@StefanWerW
Copy link
Member

@otaconwow funciona também. Guardar a referencia é faco caso queira encerrar prematuramente a Coroutine. Nesse caso nao precisa, acho que fiz por costume.

Remoção da variável moveCoroutine
@otaconwow
Copy link
Member Author

@StefanWerW okidoki, fiz novo commit com as alterações que vc propôs e removi o uso dessa variável. 👍

@StefanWerW StefanWerW merged commit 2d2111a into MuvucaGames:master May 15, 2016
@otaconwow otaconwow deleted the Bird branch May 16, 2016 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants