- Home /
How to move a gameobject when it lands on a tag, to another tag?
So im making a snakes and ladders game using waypoints, and i have assigned tags to the waypoints that are located on a snake/ladder square. However i cant figure or find out how to move the characters to the top of the ladder or bottom of the snake. I heard i can use CompareTag, but i think my main issue is figuring out ALL the code i need and where to place it for it to work.
Here is my code for the movement, i have another code for GameControl and Dice that i can post if its needed:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Movement : MonoBehaviour {
public Transform[] waypoints;
[SerializeField]
private float moveSpeed = 1f;
[HideInInspector]
public int waypointIndex = 0;
public bool moveAllowed = false;
private void Start () {
transform.position = waypoints[waypointIndex].transform.position;
}
private void Update () {
if (moveAllowed)
Move();
}
private void Move()
{
if(waypointIndex <= waypoints.Length - 1)
{
transform.position = Vector2.MoveTowards(transform.position,
waypoints[waypointIndex].transform.position,
moveSpeed * Time.deltaTime);
if (transform.position == waypoints[waypointIndex].transform.position)
{
waypointIndex += 1;
}
}
}
}
Write out everything you want to do, in steps in correct order then you will know what you need where. Often when describing the problem like that the answer becomes obvious.
I can't write the code, but you need to put the code in MonoBehaviour.OnTriggerEnter()
Your answer
![](https://koobas.hobune.stream/wayback/20220613033756im_/https://answers.unity.com/themes/thub/images/avi.jpg)