Missing body

Hello,
When I delete de Cactus in the body the same way as in the video I get the following error.
Any advice?
thank you

Hi Matei,

Open the cactus prefab in the prefab mode by double clicking on the prefab. Then remove the children. Create a new “Body”, assign the SpriteRenderer and the Animator to it. Alternatively, you could keep the animator attached to the parent.

The idea is the following: Keep the non-visual stuff attached to the parent, and the visual stuff to the child. This way, our code and the animator/animation will not cause conflicts.

Hi Nina,
Thanks for your respond, I will try this. So far I worked without deleting the body prefab and it’s seem to work alright. I also used imagines instead of quad after reading the Q&A section, because quad didn’t work.

Let me know how it worked. :slight_smile:

Worked so far. But now when I don’t have an attacker in my lane is still shooting and also if I put a cactus on lane 2 it destroys the lizard on lane 3. which is odd.
Any idea hot to solve this?
Thank you

Did you use FindObjectOfType instead of GetComponent in your code? Remember you can also look at the lecture code changes via the link in the Resources of each lecture.

Yes I had a look on the code first! Maybe if i change the collider dimension I will try that!
here is the code
thank you
"public class Shooter : MonoBehaviour
{
[SerializeField] GameObject projectile, gun;
AttackerSpawner myLaneSpawner;

private void Start()
{
    SetLaneSpawner();
}

private void Update()
{
    if (IsAttackerInLane())
    {
        Debug.Log("shoot pew pew");
        // TODO change animation state to shooting
    }
    else
    {
        Debug.Log("sit and wait");
        // TODO change animation state to idle
    }
}

private void SetLaneSpawner()
{
    AttackerSpawner[] spawners = FindObjectsOfType<AttackerSpawner>();

    foreach (AttackerSpawner spawner in spawners)
    {
        bool IsCloseEnough =
            (Mathf.Abs(spawner.transform.position.y - transform.position.y)
            <= Mathf.Epsilon);
        if (IsCloseEnough)
        {
            myLaneSpawner = spawner;
        }
    }
}

private bool IsAttackerInLane()
{
    if (myLaneSpawner.transform.childCount <= 0)
    {
        return false;
    }
    else
    {
        return true;
    }
}

public void Fire()
{
    Instantiate(projectile, gun.transform.position, transform.rotation);
}

}
"

After changing the collider dimension is not destroying the lizzard on the other lanes but is still firing.

Solved it, there were 2 shooter scripts one on the cactus and the second one from the body.

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

Privacy & Terms