I can't connect my prefabs

I was making Laser Defender game in which I had to connect my Enemy to wavepoints
I did everything shown in the video. I’m using unity 2019.4.4f1
2D game development course, Laser Defender , Udemy video number 14
Please help!

Hi Dhruveel,

Welcome to our community! :slight_smile:

Please leave your waypoints in the Hierarchy and assign the waypoints from your Hierarchy to the enemy in the Hierarchy. In one of the next lectures, Rick will create a path variable to which you can assign your prefab.

Did this help?


See also:

I can’t connect them even through Hierarchy

The screenshot shows the prefab mode. Go back to your scene, please.

image

When I add hierarchy to hierarchy the enemy object is going out of screen. My waypoints are placed in the screen proper
Before Gameplay


After Gameplay

Enemy.cs code

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

public class EnemyPathing : MonoBehaviour
{
[SerializeField] List wavepoints;
[SerializeField] float enemySpeed = 2f;
int wavepointIndex = 0;

// Start is called before the first frame update
void Start()
{
    transform.position = wavepoints[wavepointIndex].transform.position;    
}

// Update is called once per frame
void Update()
{
    if (wavepointIndex <= wavepoints.Count - 1)
    {
        var targetPosition = wavepoints[wavepointIndex].transform.position;
        var movementSpeed = enemySpeed * Time.deltaTime;
        transform.position = Vector2.MoveTowards(transform.position, targetPosition, movementSpeed);

        if (transform.position == targetPosition)
        {
            wavepointIndex++;
        }
        else
        {
            Destroy(gameObject);
        }
    }
}

}

Check the parent game object Path (0). Its position must be set to (0, 0, 0).

It is set to (0,0,0)

Could you share a screenshot of the Inspector of “enemyRed1” in your Hierarchy?

Some how i was able to add from hierarchy to hierarchy but the enemy goes out of the frame once i click on play like i shown you above

Click on the enemy in your Hierarchy when it disappears. What position does it have?

Is the position of the background game object set to z = 10?

Background Image
pos: -10, roatation: 0 and scale: 1

enemy object just gets deleted from the hierarchy after clicking on play

Done madam. In the code I had written else with the inside if and not the outside one. So now my enemy is moving properly
But i still can’t connect my prefabs directly. Only hierarchy to hierarchy

Good job on fixing the issue. :slight_smile:

Do it “hierarchy to hierarchy” because you are using a newer version of Unity than Rick and therefore the new prefab system. Rick is going to use the path prefab in one of the next lecture. Then you should be able to assign the path prefab as he does.


See also:

Okay, Thank you!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms