error CS0246: The type or namespace name 'GameManager' could not be found (are you missing a using d

Hey, I’m doing a 2d Platform Game to train my unity skills (I’m new), When I stomp on them they will die, and when I touch them (not from above) the player will die. And I need help, so here’s the script if you want to help me! :slight_smile:

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

public class Enemy : MonoBehaviour
{
    public LayerMask enemyMask;
    public float speed = 1;
    Rigidbody2D myBody;
    Transform myTrans;
    float myWidth;
   
    private GameManager gameManager;

    void Start()
    {
        myTrans = this.transform;
        myBody = this.GetComponent<Rigidbody2D>();
        myWidth = this.GetComponent<SpriteRenderer>().bounds.extents.x;
        gameManager = FindObjectOfType<GameManager>;
       
    }


    void FixedUpdate()
    {

        Vector2 lineCastPos = myTrans.position - myTrans.right * myWidth;
        bool isGrounded = Physics2D.Linecast(lineCastPos, lineCastPos + Vector2.down, enemyMask);

        if(!isGrounded)
        {
            Vector3 currRot = myTrans.eulerAngles;
            currRot.y += 180;
            myTrans.eulerAngles = currRot;

        }


        //Always move forward
        Vector2 myVel = myBody.velocity;
        myVel.x = -myTrans.right.x *speed;
        myBody.velocity = myVel;
       
    }

   
    void OnCollisionEnter2d(Collision2D coll)
    {
        if(coll.gameObject.tag == "Player")
        {
            gameManager.Respawn ();
        }
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if(other.tag == "Player")
        {
            if (other.GetComponent<Rigidbody2D> ().velocity.y <= 0f)
            {
                other.GetComponent<Rigidbody2D>().velocity = new Vector2 (rb2d.velocity.x, other.GetComponent<PlayerMovement>().jumpspeed);
                Destroy (gameObject);
            }
        }
    }

}

The error is saying that Unity is not aware of any class called GameManager. Did you write a GameManager class? If not, this won’t work.

Thanks for your reply! And no, I haven’t, I will try. :slight_smile:

I’m guessing you copied this script from a tutorial somewhere? They probably have a GameManager script as well you forgot to copy.

yes, I copied from another script, but I guess I see if I forgot something! :smile:

I dind’t miss anything, do you know how to script it?

Either you missed it or the tutorial creator failed to provide it. It’s not just a standard component, GameManager would be something that is designed for that tutorial project to fulfill a particular purpose. All we can tell about it is that it has a function called Respawn, and we don’t have any clues how it would be implemented.

You can start with this:

public class GameManager : MonoBehaviour {

public void Respawn() {
}
}

And add that script onto a GameObject in your scene.

At some point you’ll need to fill in the functionality of Respawn, but this will at least allow you to compile the first script.

When I do what you said it says error CS0103: The name 'rb2d' does not exist in the current context, error CS0428: Cannot convert method group 'FindObjectOfType' to non-delegate type 'GameManager, Did you intend to invoke the method?'." and PlayerMovement' does not contain a definition for 'jumpspeed' and no accessible extension method 'jumpspeed' accepting a first argument of type 'PlayerMovement' could be found (are you missing a using directive or an assembly reference? Sorry if I ask so much… :sweat_smile:

I think you would be better off trying a different tutorial that is more complete. I don’t think you’ll learn anything this way.

Could you link us to the tutorial you’re following? My first instinct is that you should go refer back to the tutorial, but I don’t know, it’s possible that the tutorial just sucks.

1 Like

if you have another video link it if you can.

That video is part 6 of a multipart tutorial. Try starting at part 1:

https://www.youtube.com/watch?v=dtk4f2Jq9sw

1 Like

Ok, thanks for your help! :slight_smile: