C
C#2y ago
Zagan

❔ Copying code from youtube and it doesn't work for me

I'm new to the C# scripts and i am trying to make a board game, while trying to understand how to do the movement. The code i copied from youtube doesn't work. Maybe i typed it wrong? It should show green line between the nodes but it doesnt. The code is here :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Route : MonoBehaviour
{
Transform[] childObjects;
public List<Transform> childNodeList = new List<Transform>();

void OnDrawGizmos()
{
Gizmos.color = Color.green;

FillNodes();

for (int i = 0; i < childNodeList.Count; i++)
{
Vector3 currentPos = childNodeList[i].position;
if (i >= 0)
{
Vector3 prevPos = childNodeList[i - 1].position;
Gizmos.DrawLine(prevPos, currentPos);
}
}

}

void FillNodes()
{
childNodeList.Clear();

childObjects = GetComponentsInChildren<Transform>();

foreach (Transform child in childObjects)
{
if (child != this.transform)
{
childNodeList.Add(child);
}
}
}


}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Route : MonoBehaviour
{
Transform[] childObjects;
public List<Transform> childNodeList = new List<Transform>();

void OnDrawGizmos()
{
Gizmos.color = Color.green;

FillNodes();

for (int i = 0; i < childNodeList.Count; i++)
{
Vector3 currentPos = childNodeList[i].position;
if (i >= 0)
{
Vector3 prevPos = childNodeList[i - 1].position;
Gizmos.DrawLine(prevPos, currentPos);
}
}

}

void FillNodes()
{
childNodeList.Clear();

childObjects = GetComponentsInChildren<Transform>();

foreach (Transform child in childObjects)
{
if (child != this.transform)
{
childNodeList.Add(child);
}
}
}


}
https://www.youtube.com/watch?v=d1oSQdydJsM heres the youtube video, In the intro section
xOctoManx
YouTube
Unity Tutorial: Board Game Movement
Get your Free PDF: 3 Strategies to FINISH your Game ➤ https://www.octomangames.com/subscribe-now/ Ludo Course: http://bit.ly/2Ni6Y5m ▼▼▼ More Infos here: Check em out! ▼▼▼ My Udemy Courses (up to 90% Discount) ➤ Galaga 3D : http://bit.ly/2IZQhrs ➤ Mastermind 2D : http://bit.ly/2CRoQf6 ➤ Ear money with Unity : http://bit.ly/2OZ9Akn ➤ Whack a Mo...
9 Replies
Buddy
Buddy2y ago
The code i copied from youtube doesn't work
$details
MODiX
MODiX2y ago
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
Zagan
Zagan2y ago
$code
MODiX
MODiX2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
Zagan
Zagan2y ago
when you do the code between the nodes/cubed there should be green line like this
Zagan
Zagan2y ago
but mine doesn't have it
Zagan
Zagan2y ago
and it spams this problem
Zagan
Zagan2y ago
nvm found the problem
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts