- Home /
Movement in Scroll View
I have the following problem:
In the canvas I have a scrollview that has a panel inside. Inside the panel i have some buttons and a spawner (Empty GameObject). My Idea is, when I click on the button, it dissapears, a table appears and there is another GameObject ''man'' spawned on the position of the spawner by this time. Everything works, I set the dissapearing and appearing by SetActive() but when it instantiates the man and he starts walking, he walks to the position of the table on the screen, no matter where the screen is. So when I move my screen to the right, the man does not stop at the table, he walks further to the point of the screen where the button is by the start (See image below). I think the problem is something about the anchors. I tried something with SetParent, pivot and setAnchor but it did not help for the man. I have not found any solution for this problem for many days. How do I make the man always walk to the table?
//Script attached to the man, making him move
public GameObject whereToWalk;
void Update()
{
transform.position = Vector3.MoveTowards(transform.position,whereToWalk.transform.position,3f);
}
My code for the disappearing and appearing of the buttons and instantiating the man:
public GameObject buttonn;
public GameObject buttonn1;
//spawner
public GameObject spawner;
//the man
public GameObject maenle;
public void Kaufe()
{
buttonn.SetActive(false);
buttonn1.SetActive(true);
Instantiate(maenle,spawner.transform);
}
}