0
\$\begingroup\$

This is my first game, and I'm trying to keep it simple, so just a simple platformer that works around the size of the player's character, and the character increases in size whenever they consume a pellet. I have the character's basic movement down, but I'm coming across some errors that I'm not so sure how to fix.

The way I have it set up is that I have a script attached to an empty object called 'LevelManager' that will execute actions once it's called upon (Like 'Respawn Player' and 'Grow Player'), there is a 'Pellet' script attached to the pellet that basically calls upon the 'Grow Player' function when the player touches the pellet's collision box.

LevelManager.cs

public class LevelManager : MonoBehaviour {
    public GameObject currentCheckpoint;
    private PlayerController player;

    // Use this for initialization
    void Start () {
        player = FindObjectOfType<PlayerController> ();
    }

    // Update is called once per frame
    void Update () {

    }
    public void RespawnPlayer()
    {
        Debug.Log ("Player Has Respawned");
    }
    public void GrowPlayer()
    {
        Debug.Log ("Player Has Grown");
        player.transform.localScale += new Vector2(0.5, 0.5);
    }
}

Pellet.cs

public class Pellet : MonoBehaviour {
    public LevelManager levelManager;

    // Use this for initialization
    void Start () {
        levelManager = FindObjectOfType<LevelManager>();
    }

    // Update is called once per frame
    void Update () {

    }
    void OnTiggerEnter2D(Collider2D other)
    {
        if (other.name == "Player") 
        {
            levelManager.GrowPlayer();
        }
    }
}

Also, I'm sorry I don't have the exact errors with me, something funky happened with the editor and I'm unable to locate the window for the compile errors anymore, and when the bug report I sent get's responded to, I'll add that in to make this an easier problem to tackle.

\$\endgroup\$
3
  • \$\begingroup\$ Hello and welcome to Gamedev.SE! You are asking us to debug your code, because you did something, that caused the error view to disappear. I flagged this as "debug my code", offtopic. However, try to change the "new Vector2(0.5, 0.5);" to "new Vector3(0.5, 0.5);" \$\endgroup\$ – Katu May 4 '15 at 4:00
  • \$\begingroup\$ @LevelForge just change the new Vector2(0.5, 0.5) to new Vector3(0.5f, 0.5f, 0); and this should solve your problems. PS in your Pellet class it is OnTiggerEnter2D whereas it should be OnTriggerEnter2D. Also make sure that your pellets have isTrigger set to true on their colliders. \$\endgroup\$ – EvilTak May 4 '15 at 4:35
  • \$\begingroup\$ Oh god I feel so silly, thank you both for the advice, I'll make sure I don't make another 'hey debug this for me pls thx' question, I guess I was a little tired and delirious when entering the question. \$\endgroup\$ – LevelForge May 4 '15 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.