Coding help with boss

Alright so im at the end of my argon assault and all thats left is making my boss. I wanted to try something and make it so that while you fighting/chasing the boss he lays down mines as u chase them ( mines just being spheres that i painted) now i have two ways of doing this. I can either make a regular timeline of him and then make a Time line of the mines that will be timed so it seems like hes spawning them behind him while you chase. OR i could make it so that these mines spawn at his current location every few seconds (every 3 seconds or something) but the problem with that is im not sure what code words and such i need to use. I feel like ive done something like this before using instantiate but i cant remember. help would be appreciated


public class CreateMines : MonoBehaviour
{
public GameObject ProjectilePrefab;
public float spawnTime = 1f;

private void spawnOnBoss()
{
    GameObject Mine = Instantiate(ProjectilePrefab) as GameObject;
    Mine.transform.position = new Vector3(gameObject.position);

}


This was as far as my mind let me go i didnt know what to do after this. i was trying to put the mines new position on the ship but it doesnt look like you can do it like this with vector3s

gameObject.position

I think it should be

gameObject.transform.position

I assume this script runs on your Boss object?

This should work in the end.

Mine.transform.position = gameObject.transform.position;

Also make Mine lowercase (mine) Things that start with uppercase are usualy classnames

Hey, that’s a neat idea for a boss!

You probably want to try something like this, to drop mines at a constant rate from wherever your boss object is at the time:

public class CreateMines : MonoBehaviour
{
public GameObject minePrefab;
public float spawnTime = 1f;
private float timeSinceLastMine = 0f;

private void Update() {
    timeSinceLastMine += Time.deltaTime;   // increase the timer by the frame time
    if (timeSinceLastMine >= spawnTime) {
        SpawnMine();
        timeSinceLastMine = 0f;  // reset the timer
    }
}

private void SpawnMine() {
    GameObject mine = Instantiate(minePrefab) as GameObject;
    mine.transform.position = gameObject.transform.position;
}

so i put this code on my boss and it looks like the first mine drops at its current position and then the rest of the mines drop on the last mines position instead of where the boss is.

ah nvm i forgot to put in the prefab in here.
ty
lol Thanks alot.

There seems to be a slight problem. So i put a code in my mines Destroy(gameObject, 1.5f); so that they are gone after a short time but my very first mine just comes back.

so i looked into it and it looks like there are mines spawning on the boss like i want it to and theres also mines spawning at the first mines location.

Edit: i went in and out of my level and it stopped doing that. i just needed to refresh the level it looked like lol thanks again. hope u get to try my game. ill be mostly finished with it by tuesday or so if i decide to make a home and end screen.

Thanks to you i did this lol

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms