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
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Assets/Editor/BirdEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using UnityEngine;
using System.Collections;
using UnityEditor;

[CustomEditor(typeof(MoveAtoB))]
public class BirdEditor : Editor
{
SerializedProperty pointA_SP;
SerializedProperty pointB_SP;

public void OnEnable()
{
pointA_SP = serializedObject.FindProperty("pointA");
pointB_SP = serializedObject.FindProperty("pointB");
}
public void OnSceneGUI()
{
serializedObject.Update();
MoveAtoB platform = (MoveAtoB)target;
Vector3 pointA = platform.transform.TransformPoint(new Vector3(pointA_SP.vector3Value.x, 0, 0));

Handles.color = Color.blue;

Vector3 pointB = platform.transform.TransformPoint(new Vector3(pointB_SP.vector3Value.x, 0, 0));

Handles.color = Color.blue;
pointB = Handles.FreeMoveHandle(
pointB,
Quaternion.identity,
HandleUtility.GetHandleSize(pointB) * 0.08f,
Vector3.one * 0.1f,
Handles.DotCap);

pointB_SP.vector3Value = platform.transform.InverseTransformPoint(pointB);
Handles.DrawDottedLine(pointA, pointB, 20f);

serializedObject.ApplyModifiedProperties();
}
}

12 changes: 12 additions & 0 deletions Assets/Editor/BirdEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 29 additions & 18 deletions Assets/Scripts/Elements/MoveAtoB.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
using UnityEngine;
using UnityEditor;
using System.Collections;

public class MoveAtoB : MonoBehaviour {

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);
}

void Update() {
// based on the speed set movement step
float step = speed * Time.deltaTime;
// move GameObject from current position (GameObject own position or if defined point A position) to point B
transform.position = Vector3.MoveTowards(transform.position, pointB, step);
}
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);
}
void FixedUpdate()
{
StartCoroutine(Move());
}
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. :)

{
// based on the speed set movement step
float step = speed * Time.deltaTime;
// move GameObject from current position (GameObject own position or if defined point A position) to point B
transform.position = Vector3.MoveTowards(transform.position, pointB, step);
yield return null;
}
}
}