Skip to main content
Bumped by Community user
deleted 164 characters in body
Source Link
House
  • 73.3k
  • 17
  • 185
  • 273

I have some trouble finding out how I can load my character at the start of the level, instead of resetingresetting the whole thing. The game mechanics are quite straight forward; don't touch the walls. If the player touches the walls, he "pops" (seeing as it is a balloon.)

This is my current script:

public class playerSpawner : MonoBehaviour {

public Sprite charAlive, charDead;
public AudioClip popAudio;

void  OnCollisionEnter2D (Collision2D col ){

    if (col.gameObject.name == "dirtWalls") {
        AudioSource.PlayClipAtPoint(popAudio, transform.position);
        gameObject.GetComponent<SpriteRenderer>().sprite = charDead;
        StartCoroutine (Dead ());
    }
    if (col.gameObject.name == "gooWalls") {
        gameObject.GetComponent<SpriteRenderer>().sprite = charDead;
        StartCoroutine (Dead ());
    }
    if (col.gameObject.name == "grassWalls") {
        gameObject.GetComponent<SpriteRenderer>().sprite = charDead;
        StartCoroutine (Dead ());
    }
}

IEnumerator Dead() {
    
    AudioSource.PlayClipAtPoint(popAudio, transform.position); // PLAYS SEVERAL TIMES
    yield return new WaitForSeconds(3/2);
    Application.LoadLevel ("untitled");
    // LOAD LEVEL RESETS EVERYTHING, MAKE LOAD CHAR INSTEAD?
}

}

It also feels like my collision is not optimal, as code should be kept as small and solid as possible. So I actually have another question to go along with my title: CouldHow can I make a parent ofjust respawn the walls and make it play through allplayer object instead of resetting the wallswhole scene?

I have some trouble finding out how I can load my character at the start of the level, instead of reseting the whole thing. The game mechanics are quite straight forward; don't touch the walls. If the player touches the walls, he "pops" (seeing as it is a balloon.)

This is my current script:

public class playerSpawner : MonoBehaviour {

public Sprite charAlive, charDead;
public AudioClip popAudio;

void  OnCollisionEnter2D (Collision2D col ){

    if (col.gameObject.name == "dirtWalls") {
        AudioSource.PlayClipAtPoint(popAudio, transform.position);
        gameObject.GetComponent<SpriteRenderer>().sprite = charDead;
        StartCoroutine (Dead ());
    }
    if (col.gameObject.name == "gooWalls") {
        gameObject.GetComponent<SpriteRenderer>().sprite = charDead;
        StartCoroutine (Dead ());
    }
    if (col.gameObject.name == "grassWalls") {
        gameObject.GetComponent<SpriteRenderer>().sprite = charDead;
        StartCoroutine (Dead ());
    }
}

IEnumerator Dead() {
    
    AudioSource.PlayClipAtPoint(popAudio, transform.position); // PLAYS SEVERAL TIMES
    yield return new WaitForSeconds(3/2);
    Application.LoadLevel ("untitled");
    // LOAD LEVEL RESETS EVERYTHING, MAKE LOAD CHAR INSTEAD?
}

}

It also feels like my collision is not optimal, as code should be kept as small and solid as possible. So I actually have another question to go along with my title: Could I make a parent of the walls and make it play through all the walls?

I have some trouble finding out how I can load my character at the start of the level, instead of resetting the whole thing. The game mechanics are quite straight forward; don't touch the walls. If the player touches the walls, he "pops" (seeing as it is a balloon.)

This is my current script:

public class playerSpawner : MonoBehaviour {

public Sprite charAlive, charDead;
public AudioClip popAudio;

void  OnCollisionEnter2D (Collision2D col ){

    if (col.gameObject.name == "dirtWalls") {
        AudioSource.PlayClipAtPoint(popAudio, transform.position);
        gameObject.GetComponent<SpriteRenderer>().sprite = charDead;
        StartCoroutine (Dead ());
    }
    if (col.gameObject.name == "gooWalls") {
        gameObject.GetComponent<SpriteRenderer>().sprite = charDead;
        StartCoroutine (Dead ());
    }
    if (col.gameObject.name == "grassWalls") {
        gameObject.GetComponent<SpriteRenderer>().sprite = charDead;
        StartCoroutine (Dead ());
    }
}

IEnumerator Dead() {
    
    AudioSource.PlayClipAtPoint(popAudio, transform.position); // PLAYS SEVERAL TIMES
    yield return new WaitForSeconds(3/2);
    Application.LoadLevel ("untitled");
    // LOAD LEVEL RESETS EVERYTHING, MAKE LOAD CHAR INSTEAD?
}

}

How can I just respawn the player object instead of resetting the whole scene?

Source Link

Load character instead of load level

I have some trouble finding out how I can load my character at the start of the level, instead of reseting the whole thing. The game mechanics are quite straight forward; don't touch the walls. If the player touches the walls, he "pops" (seeing as it is a balloon.)

This is my current script:

public class playerSpawner : MonoBehaviour {

public Sprite charAlive, charDead;
public AudioClip popAudio;

void  OnCollisionEnter2D (Collision2D col ){

    if (col.gameObject.name == "dirtWalls") {
        AudioSource.PlayClipAtPoint(popAudio, transform.position);
        gameObject.GetComponent<SpriteRenderer>().sprite = charDead;
        StartCoroutine (Dead ());
    }
    if (col.gameObject.name == "gooWalls") {
        gameObject.GetComponent<SpriteRenderer>().sprite = charDead;
        StartCoroutine (Dead ());
    }
    if (col.gameObject.name == "grassWalls") {
        gameObject.GetComponent<SpriteRenderer>().sprite = charDead;
        StartCoroutine (Dead ());
    }
}

IEnumerator Dead() {
    
    AudioSource.PlayClipAtPoint(popAudio, transform.position); // PLAYS SEVERAL TIMES
    yield return new WaitForSeconds(3/2);
    Application.LoadLevel ("untitled");
    // LOAD LEVEL RESETS EVERYTHING, MAKE LOAD CHAR INSTEAD?
}

}

It also feels like my collision is not optimal, as code should be kept as small and solid as possible. So I actually have another question to go along with my title: Could I make a parent of the walls and make it play through all the walls?