Ask coding questions

← Back to all posts
Unity help
Bunnytoes (142)

My code is making the bullet not work if there is no target. also if the original enemy dies the next waves don't spawn here are the screenshots

Comments
hotnewtop
Coder100 (18123)

the error probably came from target make sure you aren't destroying that anywhere else

Bunnytoes (142)

@Coder100 I beleive that the error is comingfrom it destroying the bullet, as when I run it no bullets are shot, but if I remove that code it says that it's missing null referance. Also the other enemies are clones so if the first enemy is destroyed they stop spawning

Coder100 (18123)

still check
and also make sure you have set all references @Bunnytoes

Bunnytoes (142)

@Coder100 idk what you mean but here is the wavespawner script

Coder100 (18123)

So in the ide, did you set all the values? @Bunnytoes

Bunnytoes (142)

@Coder100 I am using visual studios. Here are the screenshots(note the target is empty because it gets a target if in range)

Coder100 (18123)

Well yeah ur using visual studio, what I meant was the unity editor which is an ide @Bunnytoes

Bunnytoes (142)

@Coder100 I don't know what you mean but I have the scripts in unity. Also the code works for brackeys

Bunnytoes (142)

@Coder100 I fixed one error but removing the destroy(gameobject) but I still need waves to spawn when the original enemy dies

Coder100 (18123)

in your gamemaster, you could make a script to spawn them @Bunnytoes

Bunnytoes (142)

@Coder100 could you please leave the code in a comment for me, it would help me so much! P.S. I just added spawning turrets so it is very needed

Coder100 (18123)

sure

public GameObject enemy;

// ...

Instantiate(enemy, Quaternion.indentity, <ur position>);

@Bunnytoes

Bunnytoes (142)

@Coder100 1.can you put all the code(thank you u but that will be more helpful)2. I fixed the bullets issue

Coder100 (18123)

sure
something like

class GameMaster : MonoBehavior {
  public GameObject enemy;

  public createEnemy() {
    Instantiate(enemy, Quaternion.indentity, <ur position>);
  }
}

@Bunnytoes
replace <ur position> and just call createEnemy whenever

Bunnytoes (142)

@Coder100 do you mean

transform.position, transform.rotation

? also should I add a new script to gamemaster?also I just need a way to instaniate the object destroyed or not destroyed

Coder100 (18123)

if you gave the line numbers in your screenshot that would have helped a lot more

Bunnytoes (142)

@Coder100 ok give me a sec here they are