My "solution" to the challege

Trying to solve the challege Ben propose in this video I came up with the following solution. I used the tag property in the waypoints game object to identify one is the start and who is the end. Then I create a function inside waypoint to set color of the top plane according to the tag. I used this function in the cubeeditor script then to make this visible in the cubeeditor script. I don-t which are the flaws in this way to do things. Any comment are more than welcome

using UnityEngine;

public class Waypoint : MonoBehaviour {

const int snapGrid = 10;
Vector2Int gridPos;

// Use this for initialization
void Update ()
{


}

public int GetSnapGrid()
{
    return snapGrid;
}

public Vector2Int GetGridPos()
{
    return gridPos = new Vector2Int
        (
          Mathf.RoundToInt(transform.position.x / snapGrid) * snapGrid,
          Mathf.RoundToInt(transform.position.z / snapGrid) * snapGrid
        );
}
public void SetTopColor(Color color)
{
    MeshRenderer topMeshRenderer = transform.Find("plusY").GetComponent<MeshRenderer>();
    topMeshRenderer.material.color = color;
}
public void DetectWaypointType()
{
    switch (gameObject.tag)
    {
        case "Finish":
            SetTopColor(Color.red);
            break;
        case "Respawn":
            SetTopColor(Color.blue);
            break;
        default:
            SetTopColor(Color.gray);
            break;

    }
        
}

}

public class CubeControl : MonoBehaviour
{
Waypoint waypoint;
// Update is called once per frame
private void Awake()
{
waypoint = GetComponent();
}
void Update()
{
Positioning();
labeling();
waypoint.DetectWaypointType();
}

Privacy & Terms