Skip to main content
deleted 1 character in body
Source Link
Hubaka Gs
  • 43
  • 2
  • 10

I have a spawn function which is

public void spawnobstacle(){
    number_of_spawn = Random.Range (1, 3);
        if (number_of_spawn > 0) {
            spawnposition = Random.Range (0, 3);
            if (spawnposition == 0 && !rightisoccupied) {
                Instantiate (obstacle, rightpos, Quaternion.identity);
                rightisoccupied = true;
            }
            if (spawnposition == 1 && !midisoccupied) {
                Instantiate (obstacle, midpos, Quaternion.identity);
                midisoccupied = true;
            }
                if (spawnposition == 2 && !leftisoccupied) {
                Instantiate (obstacle, leftpos, Quaternion.identity);
                leftisoccupied = true;
            }
            number_of_spawn -= 1;
    } 

and I have another script in the obstacle GameObject that if the obstacle is triggered by it, it destroys the obstacle and spawn some other obstacle.

The content of the script is this:

public class DestroyObstacle : MonoBehaviour {
public GameObject world;
void OnTriggerEnter2D (Collider2D thecollision){
    if (thecollision.gameObject.tag == "destroypoint1") {

        world.GetComponent<Spawn> ().spawnobstacle ();
        Destroy (this.gameObject);
    }
}
void Start(){
    world = GameObject.Find ("World");
    }
void Update() {
    
}

ProblemWhy is, the function only calls one obstacle every time and the function is called only once, 2 times max (not every time the obstacle is destroyed)?

I have a spawn function which is

public void spawnobstacle(){
    number_of_spawn = Random.Range (1, 3);
        if (number_of_spawn > 0) {
            spawnposition = Random.Range (0, 3);
            if (spawnposition == 0 && !rightisoccupied) {
                Instantiate (obstacle, rightpos, Quaternion.identity);
                rightisoccupied = true;
            }
            if (spawnposition == 1 && !midisoccupied) {
                Instantiate (obstacle, midpos, Quaternion.identity);
                midisoccupied = true;
            }
                if (spawnposition == 2 && !leftisoccupied) {
                Instantiate (obstacle, leftpos, Quaternion.identity);
                leftisoccupied = true;
            }
            number_of_spawn -= 1;
    } 

and I have another script in the obstacle GameObject that if the obstacle is triggered by it, it destroys the obstacle and spawn some other obstacle.

The content of the script is this:

public class DestroyObstacle : MonoBehaviour {
public GameObject world;
void OnTriggerEnter2D (Collider2D thecollision){
    if (thecollision.gameObject.tag == "destroypoint1") {

        world.GetComponent<Spawn> ().spawnobstacle ();
        Destroy (this.gameObject);
    }
}
void Start(){
    world = GameObject.Find ("World");
    }
void Update() {
    
}

Problem is, function only calls one obstacle every time and the function is called only once, 2 times max (not every time the obstacle is destroyed)?

I have a spawn function which is

public void spawnobstacle(){
    number_of_spawn = Random.Range (1, 3);
        if (number_of_spawn > 0) {
            spawnposition = Random.Range (0, 3);
            if (spawnposition == 0 && !rightisoccupied) {
                Instantiate (obstacle, rightpos, Quaternion.identity);
                rightisoccupied = true;
            }
            if (spawnposition == 1 && !midisoccupied) {
                Instantiate (obstacle, midpos, Quaternion.identity);
                midisoccupied = true;
            }
                if (spawnposition == 2 && !leftisoccupied) {
                Instantiate (obstacle, leftpos, Quaternion.identity);
                leftisoccupied = true;
            }
            number_of_spawn -= 1;
    } 

and I have another script in the obstacle GameObject that if the obstacle is triggered by it, it destroys the obstacle and spawn some other obstacle.

The content of the script is this:

public class DestroyObstacle : MonoBehaviour {
public GameObject world;
void OnTriggerEnter2D (Collider2D thecollision){
    if (thecollision.gameObject.tag == "destroypoint1") {

        world.GetComponent<Spawn> ().spawnobstacle ();
        Destroy (this.gameObject);
    }
}
void Start(){
    world = GameObject.Find ("World");
    }
void Update() {
    
}

Why is the function only calls one obstacle every time and the function is called only once, 2 times max (not every time the obstacle is destroyed)?

Questions in inquiry are actually optional
Source Link
Hubaka Gs
  • 43
  • 2
  • 10

Why is my function Function called only once from another script?

I have a spawn function which is

public void spawnobstacle(){
    number_of_spawn = Random.Range (1, 3);
        if (number_of_spawn > 0) {
            spawnposition = Random.Range (0, 3);
            if (spawnposition == 0 && !rightisoccupied) {
                Instantiate (obstacle, rightpos, Quaternion.identity);
                rightisoccupied = true;
            }
            if (spawnposition == 1 && !midisoccupied) {
                Instantiate (obstacle, midpos, Quaternion.identity);
                midisoccupied = true;
            }
                if (spawnposition == 2 && !leftisoccupied) {
                Instantiate (obstacle, leftpos, Quaternion.identity);
                leftisoccupied = true;
            }
            number_of_spawn -= 1;
    } 

and I have another script in the obstacle GameObject that if the obstacle is triggered by it, it destroys the obstacle and spawn some other obstacle.

The content of the script is this:

public class DestroyObstacle : MonoBehaviour {
public GameObject world;
void OnTriggerEnter2D (Collider2D thecollision){
    if (thecollision.gameObject.tag == "destroypoint1") {

        world.GetComponent<Spawn> ().spawnobstacle ();
        Destroy (this.gameObject);
    }
}
void Start(){
    world = GameObject.Find ("World");
    }
void Update() {
    
}

WhyProblem is the spawn, function only calls one obstacle every time and the function is called only once, 2 times max (not every time the obstacle is destroyed)?

Why is my function called only once from another script?

I have a spawn function which is

public void spawnobstacle(){
    number_of_spawn = Random.Range (1, 3);
        if (number_of_spawn > 0) {
            spawnposition = Random.Range (0, 3);
            if (spawnposition == 0 && !rightisoccupied) {
                Instantiate (obstacle, rightpos, Quaternion.identity);
                rightisoccupied = true;
            }
            if (spawnposition == 1 && !midisoccupied) {
                Instantiate (obstacle, midpos, Quaternion.identity);
                midisoccupied = true;
            }
                if (spawnposition == 2 && !leftisoccupied) {
                Instantiate (obstacle, leftpos, Quaternion.identity);
                leftisoccupied = true;
            }
            number_of_spawn -= 1;
    } 

and I have another script in the obstacle GameObject that if the obstacle is triggered by it, it destroys the obstacle and spawn some other obstacle.

The content of the script is this:

public class DestroyObstacle : MonoBehaviour {
public GameObject world;
void OnTriggerEnter2D (Collider2D thecollision){
    if (thecollision.gameObject.tag == "destroypoint1") {

        world.GetComponent<Spawn> ().spawnobstacle ();
        Destroy (this.gameObject);
    }
}
void Start(){
    world = GameObject.Find ("World");
    }
void Update() {
    
}

Why is the spawn function only calls one obstacle every time and the function is called only once, 2 times max (not every time the obstacle is destroyed)?

Function called only once from another script

I have a spawn function which is

public void spawnobstacle(){
    number_of_spawn = Random.Range (1, 3);
        if (number_of_spawn > 0) {
            spawnposition = Random.Range (0, 3);
            if (spawnposition == 0 && !rightisoccupied) {
                Instantiate (obstacle, rightpos, Quaternion.identity);
                rightisoccupied = true;
            }
            if (spawnposition == 1 && !midisoccupied) {
                Instantiate (obstacle, midpos, Quaternion.identity);
                midisoccupied = true;
            }
                if (spawnposition == 2 && !leftisoccupied) {
                Instantiate (obstacle, leftpos, Quaternion.identity);
                leftisoccupied = true;
            }
            number_of_spawn -= 1;
    } 

and I have another script in the obstacle GameObject that if the obstacle is triggered by it, it destroys the obstacle and spawn some other obstacle.

The content of the script is this:

public class DestroyObstacle : MonoBehaviour {
public GameObject world;
void OnTriggerEnter2D (Collider2D thecollision){
    if (thecollision.gameObject.tag == "destroypoint1") {

        world.GetComponent<Spawn> ().spawnobstacle ();
        Destroy (this.gameObject);
    }
}
void Start(){
    world = GameObject.Find ("World");
    }
void Update() {
    
}

Problem is, function only calls one obstacle every time and the function is called only once, 2 times max (not every time the obstacle is destroyed)?

Forgot to add my inquiry a question.
Source Link
Hubaka Gs
  • 43
  • 2
  • 10

I have a spawn function which is

public void spawnobstacle(){
    number_of_spawn = Random.Range (1, 3);
        if (number_of_spawn > 0) {
            spawnposition = Random.Range (0, 3);
            if (spawnposition == 0 && !rightisoccupied) {
                Instantiate (obstacle, rightpos, Quaternion.identity);
                rightisoccupied = true;
            }
            if (spawnposition == 1 && !midisoccupied) {
                Instantiate (obstacle, midpos, Quaternion.identity);
                midisoccupied = true;
            }
                if (spawnposition == 2 && !leftisoccupied) {
                Instantiate (obstacle, leftpos, Quaternion.identity);
                leftisoccupied = true;
            }
            number_of_spawn -= 1;
    } 

and I have another script in the obstacle GameObject that if the obstacle is triggered by it, it destroys the obstacle and spawn some other obstacle.

The content of the script is this:

public class DestroyObstacle : MonoBehaviour {
public GameObject world;
void OnTriggerEnter2D (Collider2D thecollision){
    if (thecollision.gameObject.tag == "destroypoint1") {

        world.GetComponent<Spawn> ().spawnobstacle ();
        Destroy (this.gameObject);
    }
}
void Start(){
    world = GameObject.Find ("World");
    }
void Update() {
    
}

ProblemWhy is, the spawn function only calls one obstacle every time and the function is called only once, 2 times max (not every time the obstacle is destroyed).?

I have a spawn function which is

public void spawnobstacle(){
    number_of_spawn = Random.Range (1, 3);
        if (number_of_spawn > 0) {
            spawnposition = Random.Range (0, 3);
            if (spawnposition == 0 && !rightisoccupied) {
                Instantiate (obstacle, rightpos, Quaternion.identity);
                rightisoccupied = true;
            }
            if (spawnposition == 1 && !midisoccupied) {
                Instantiate (obstacle, midpos, Quaternion.identity);
                midisoccupied = true;
            }
                if (spawnposition == 2 && !leftisoccupied) {
                Instantiate (obstacle, leftpos, Quaternion.identity);
                leftisoccupied = true;
            }
            number_of_spawn -= 1;
    } 

and I have another script in the obstacle GameObject that if the obstacle is triggered by it, it destroys the obstacle and spawn some other obstacle.

The content of the script is this:

public class DestroyObstacle : MonoBehaviour {
public GameObject world;
void OnTriggerEnter2D (Collider2D thecollision){
    if (thecollision.gameObject.tag == "destroypoint1") {

        world.GetComponent<Spawn> ().spawnobstacle ();
        Destroy (this.gameObject);
    }
}
void Start(){
    world = GameObject.Find ("World");
    }
void Update() {
    
}

Problem is, the spawn function only calls one obstacle every time and the function is called only once, 2 times max (not every time the obstacle is destroyed).

I have a spawn function which is

public void spawnobstacle(){
    number_of_spawn = Random.Range (1, 3);
        if (number_of_spawn > 0) {
            spawnposition = Random.Range (0, 3);
            if (spawnposition == 0 && !rightisoccupied) {
                Instantiate (obstacle, rightpos, Quaternion.identity);
                rightisoccupied = true;
            }
            if (spawnposition == 1 && !midisoccupied) {
                Instantiate (obstacle, midpos, Quaternion.identity);
                midisoccupied = true;
            }
                if (spawnposition == 2 && !leftisoccupied) {
                Instantiate (obstacle, leftpos, Quaternion.identity);
                leftisoccupied = true;
            }
            number_of_spawn -= 1;
    } 

and I have another script in the obstacle GameObject that if the obstacle is triggered by it, it destroys the obstacle and spawn some other obstacle.

The content of the script is this:

public class DestroyObstacle : MonoBehaviour {
public GameObject world;
void OnTriggerEnter2D (Collider2D thecollision){
    if (thecollision.gameObject.tag == "destroypoint1") {

        world.GetComponent<Spawn> ().spawnobstacle ();
        Destroy (this.gameObject);
    }
}
void Start(){
    world = GameObject.Find ("World");
    }
void Update() {
    
}

Why is the spawn function only calls one obstacle every time and the function is called only once, 2 times max (not every time the obstacle is destroyed)?

deleted 8 characters in body; edited tags; edited title
Source Link
Vaillancourt
  • 16.4k
  • 17
  • 56
  • 61
Loading
Source Link
Hubaka Gs
  • 43
  • 2
  • 10
Loading