I don’t have the right arrow beside the prefab icon on Project view to expand and the link the waypoints to the enemy.
I"ve created the game object and nested items just as explained in the lesson.
Did I miss something?
I don’t have the right arrow beside the prefab icon on Project view to expand and the link the waypoints to the enemy.
I"ve created the game object and nested items just as explained in the lesson.
Did I miss something?
I don’t have that either.
Hi @marcelcorradi, hi @2Drocket,
Are you using Unity 2018.3 or a later version? If so, the prefab system works differently. You cannot expand the prefab anymore. Double click on it to open the prefab in the prefab mode. There you can edit it. When you are done, click on the arrow in the Hierarchy.
Hi Nina,
Thank you, but in this lesson they want us to connect the three waypoints in the Path prefab to the Enemy prefab. I tried dragging them from the Hierarchy to the Enemy prefab but it won’t allow it.
Yes, this is 2019.1 version.
Here is what I did and it solved for now. But I didn’t use a List, I created a SerializedField Path and added the prefab to it, then I called the method to get the component Transform from it childs and added it to a Array of Transform. Here is the code:
public class EnemyPathing : MonoBehaviour
{
[SerializeField] GameObject path;
[SerializeField] float moveSpeed = 2f;
Transform[] waypoints;
int waypointIndex = 1;
// Start is called before the first frame update
void Start()
{
waypoints = path.GetComponentsInChildren<Transform>();
transform.position = waypoints[waypointIndex].transform.position;
foreach (Transform waypoint in waypoints)
{
Debug.Log("Waypoint: " + waypoint.position);
Debug.Log("Waypoint NAme: " + waypoint.name);
}
}
// Update is called once per frame
void Update()
{
MoveEnemy();
}
private void MoveEnemy()
{
if (waypointIndex <= waypoints.Length - 1)
{
var targetPosition = waypoints[waypointIndex].transform.position;
var movementThisFrame = moveSpeed * Time.deltaTime;
transform.position = Vector2.MoveTowards(transform.position, targetPosition, movementThisFrame);
if (transform.position == targetPosition)
{
waypointIndex++;
}
}
else
{
Destroy(gameObject);
}
}
}
Drag the prefab into your Hierarchy, keep it there and drag the children from the Hierarchy into the empty fields in your enemy’s Inspector. Do not remove the path game object or the waypoints from your Hierarchy.
In lecture 98, Rick will replace the single waypoints with a slightly different solution. That solution will work with the new prefab system.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.