#do u have the time to follow me through

1 messages · Page 1 of 1 (latest)

iron siren
#

so, do you know how to create a variable?

frank hazel
#

like floats?

iron siren
#

i feel like it's the simplest thing that you need to know

frank hazel
#

floats are variables right

#

and ints that can change

iron siren
#

well yeah anyway, are you creating a project for school or something

#

is it something time-limited

frank hazel
#

project due in 30 mins but i have most of the stuff that is neccesary, all i need now is this

iron siren
#

well then i dont think i can walk you through it

frank hazel
#

ah rip

iron siren
#

i have to give you a ready code snippet and later you can analyze it and draw conclusions from it

frank hazel
#

if you want to give that would be amazing

iron siren
#

where do you spawn enemies? or do you just put them in the hierarchy

frank hazel
#

cuz i am interested in knowing more

#

i just put them in the hierarchy

iron siren
#

do they have any script on them?

frank hazel
#

theres like 14 spread out over the level

iron siren
#

yeah but do they have any custom script on them

frank hazel
#

2 separate scripts

#

1 enemy is called enemy and has the hp script and a movement script

#

the other enemy rn just has a script of upon collision, deal 100 damage and destroy itself, so no hp script yet

iron siren
#

i guess what youre talking about is functions

#

now

frank hazel
#

oh sorry

iron siren
#

anyway can you send the enemy script or whatever

frank hazel
#

i was unsure which script u meant so i sent these

#

cuz it has several

iron siren
#

okay create a new script called gamemanager or do you have one already

frank hazel
#

not yet

iron siren
#

then create one

frank hazel
#

alr

#

i did

iron siren
#
public int enemyCount;

public static GameManager Instance { get; private set; }

private void Awake() {
  Instance = this;
} 
#

this is what you'll put in it

frank hazel
#

aight

#

and what else

iron siren
#

and change the enemy script to this

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy : MonoBehaviour
{

    public int health = 100;

    public GameObject deathEffect;

    private void OnEnable() {
      GameManager.Instance.enemyCount++;
    }

    public void TakeDamage(int damage)
    {
        health -= damage;

        if (health <= 0)
        {
            Die();
        }
    }

    void Die()
    {
        GameManager.Instance.enemyCount--;
        Destroy(gameObject);
    }

}

#

and change the gamemanager script to this

#
public int enemyCount = 0;

public static GameManager Instance { get; private set; }

private void Awake() {
  Instance = this;
}

private void Update() {
  if(enemyCount == 0) {
    //win condition
  }
}
frank hazel
#

ok

#

i did

iron siren
#

thats basically all

frank hazel
#

aight

#

and on the win condition

#

i can basically do like a new screen with go to new scene

iron siren
#

i guess you can just change the scene yea

frank hazel
#

aight cool man

#

lemme test it

#

Object reference not set to an instance of an object

#

at enemy.cs29

iron siren
#

so which line is it?

#

copy and paste that line

frank hazel
#

line 29

#

GameManager.Instance.enemyCount--;

iron siren
#

oh right i forgot

#

make an empty gameobject in the scene

#

and add the "GameManager" script to it

frank hazel
#

YES

#

IT DO BE WORKING

#

could kiss u rn ngl

#

thx

#

wait but when theres 2 enemies now

#

when i only kill 1

#

it goes to the next scene

iron siren
#

where did you put the scene change

frank hazel
#

in the gamemanager

#

as win condition

iron siren
#

can you send it?

frank hazel
#

private void Update()
{
if (enemyCount == 0)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
}

iron siren
#

are you sure all enemies hve the "Enemy" script

frank hazel
#

yes

#

because i edited the og script

#

oh wait i think i fixed it

#

i just do +1 in gamemanager

#

yes, fixed it myself

#

thanks for helping