I have a script for a board game I am making. each character has different abilities and such but in trying to get spaces that are supposed to automatically move the player forward or backward the script won’t even detect a simple collision. here is the script that is not working. I am just beginning my game dev career and still don’t quite understand all of the syntax so if something is wrong please tell me and explain it like you are talking to a four-year-old. Thank you.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FireKid : MonoBehaviour
{
public string characterName = "";
public string moveSpaceTag = "";
public int currentWaypoint;
public int targetWaypoint;
public int waypointsMoved = 0;
public int diceRoll;
public float moveSpeed = 5;
public bool startedTurn = false;
public TurnManager tm;
public WaypointManager wm;
public bool isOnMoveSpace = false;
public GameObject lastMoveSpace;
void Start()
{
tm = FindObjectOfType<TurnManager>();
wm = FindObjectOfType<WaypointManager>();
for (int i = 0; i < tm.activePlayers.Length; i++)
{
if (tm.activePlayers[i].name == characterName);
}
}
void Update()
{
if (tm.activePlayers[tm.playerTurn].name == characterName)
{
if (Input.GetKeyDown(KeyCode.E) && !startedTurn)
{
startedTurn = true;
RollDie();
}
if (startedTurn)
{
if (Vector2.Distance(this.gameObject.transform.position, wm.waypoints[currentWaypoint + waypointsMoved].transform.position) == 0)
waypointsMoved++;
if (currentWaypoint <= targetWaypoint)
{
this.gameObject.transform.position = Vector2.MoveTowards(this.gameObject.transform.position, wm.waypoints[currentWaypoint + waypointsMoved].transform.position, moveSpeed * Time.deltaTime);
}
if (Vector2.Distance(this.gameObject.transform.position, wm.waypoints[targetWaypoint].transform.position) == 0)
{
startedTurn = false;
currentWaypoint = targetWaypoint;
//diceRoll = 0;
waypointsMoved = 0;
if (isOnMoveSpace == true)
{
MovementSpace movementSpace = lastMoveSpace.GetComponent<MovementSpace>();
targetWaypoint = movementSpace.spacesToMove;
isOnMoveSpace = false;
}
tm.NextTurn();
}
}
}
}
public void RollDie()
{
diceRoll = Random.Range(1, 7);
if (targetWaypoint < wm.waypoints.Length - diceRoll)
targetWaypoint += diceRoll;
else
targetWaypoint = wm.waypoints.Length - 1;
}
public void OnTriggerStay2D(Collider2D collision)
{
Debug.Log("Collision.");
}
}