- Home /
Question by
jacek331 · Oct 31, 2017 at 02:44 PM ·
2d gamemovinggameobject
2d moving by button one by one
Hi. Im trying to do game. I want take a way for moving by set and special blocks. Problem is if i use for example blocks for 'south' and 'east' he is just moving accross not one by one, first to south, then to east. Anyone know how to fix it? Here is my code:
void check(){
//s = GetComponent<Slot>();
for (int i = 0; i < 14; i++) {
listaaa.Add (GameObject.Find ("Slot" + i));
print ("Slot"+i+" dodany do listy");
}
GameObject go = GameObject.Find("professor");
animator = go.GetComponent<Animator>();
foreach (GameObject item in listaaa) {
if (item.transform.childCount > 0) {
if (item.transform.GetChild (0).name == "East")
{
animator.SetInteger ("Direction", 3);
listawektorow.Add(new Vector3(4,0,0));
print ("poszedl w prawo");
}
if (item.transform.GetChild (0).name == "West")
{
animator.SetInteger("Direction", 1);
go.transform.Translate (Vector3.left * 4);
print ("poszedl w lewo");
}
if (item.transform.GetChild (0).name == "North")
{
animator.SetInteger("Direction", 2);
go.transform.Translate (Vector3.up * 4);
print ("poszedl w gore");
}
if (item.transform.GetChild (0).name == "South")
{
animator.SetInteger("Direction", 0);
listawektorow.Add (new Vector3(0,-4,0));
print ("poszedl w dol");
}
}
}
listaaa.Clear ();
dlwek = listawektorow.Count;
for (int i = 0; i < dlwek; i++)
{
relativeLocation = listawektorow[i];
float timeDelta = 0.05f;
Vector3 targetLocation = go.transform.position + relativeLocation;
this.StartCoroutine (SmoothMove (targetLocation, timeDelta));
}
listawektorow.Clear ();
}
Comment
Your answer
Follow this Question
Related Questions
How to make an 2d object jump from A point to B point? 0 Answers
How to decide an object's position when using Instantiate? 1 Answer
How can I force a device to recognize touches from large surfaces like the bottom of a hand? 0 Answers
How to make lane switching in mobile endless runner using UI buttons? 1 Answer
How to smooth out character Roll in a Top-down 2D movement 0 Answers