#do u have the time to follow me through
1 messages · Page 1 of 1 (latest)
like floats?
i feel like it's the simplest thing that you need to know
well yeah anyway, are you creating a project for school or something
is it something time-limited
project due in 30 mins but i have most of the stuff that is neccesary, all i need now is this
well then i dont think i can walk you through it
ah rip
i have to give you a ready code snippet and later you can analyze it and draw conclusions from it
if you want to give that would be amazing
where do you spawn enemies? or do you just put them in the hierarchy
do they have any script on them?
theres like 14 spread out over the level
yeah but do they have any custom script on them
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
oh sorry
anyway can you send the enemy script or whatever
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
i was unsure which script u meant so i sent these
cuz it has several
okay create a new script called gamemanager or do you have one already
not yet
then create one
public int enemyCount;
public static GameManager Instance { get; private set; }
private void Awake() {
Instance = this;
}
this is what you'll put in it
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
}
}
thats basically all
aight
and on the win condition
i can basically do like a new screen with go to new scene
i guess you can just change the scene yea
aight cool man
lemme test it
Object reference not set to an instance of an object
at enemy.cs29
oh right i forgot
make an empty gameobject in the scene
and add the "GameManager" script to it
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
where did you put the scene change
can you send it?
private void Update()
{
if (enemyCount == 0)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
}
are you sure all enemies hve the "Enemy" script