Hello, I’m Kate and I’m entering the world of game developer and been having dificulties for 2 weeks now, if anyone can help me I’ll be very grateful.
I’m making a 3D Space Ship game and I’m having a hard time in the Hero, Enemy and Boss life.
When I press play:
1 - Enemies take damage and die - Ok
2 - Boss takes damage, dies but doesn’t load new scene -
3 - And the Hero takes only 1 damage and dies, even though I put 3 lives for him. (In HUD of 3 goes to 0 of lives)
The script is in:
Hero
Boss
Enemy
Hero = 3 lives
Boss = 10 lives
Enemy = 2 lives
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Destroy_of_Object_contact : MonoBehaviour
{
public GameObject enemyexplosion;
public GameObject Ship_Hero;
public int PointValue;
public int LiveHero;
private GameControl gamecontrol;
public int LiveEnemy;
public int Damage;
void Start()
{
GameObject GameControlobject = GameObject.FindWithTag ("GameController");
if (GameControlobject != null)
{
gamecontrol = GameControlobject.GetComponent <GameControl>();
}
if (gamecontrol == null)
{
Debug.Log ("Cannot find 'ControleDoGame' script");
}
}
private void OnTriggerEnter(Collider Object)
{
if (Object.tag == ("Shooting Barriers") || Object.CompareTag("Enemy") || Object.CompareTag("Boss"))
{
return;
}
if (enemyexplosion != null)
{
LiveEnemy = LiveEnemy - Damage;
if (LiveEnemy <= 0)
{
gamecontrol.AddPoints(PointValue);
Destroy(Object.gameObject);
Destroy(gameObject);
}
Instantiate(enemyexplosion, transform.position, transform.rotation);
}
if (Object.tag == "Boss")
{
if (LiveEnemy <= 0)
{
SceneManager.LoadScene("NewScene");
}
Instantiate(enemyexplosion, transform.position, transform.rotation);
}
if (Object.tag == "Player")
{
gamecontrol.RemoveLives(LiveHero);
if (LiveHero <= 0)
{
SceneManager.LoadScene("GameOver");
Destroy(Object.gameObject);
Destroy(gameObject);
}
Instantiate(Ship_Hero, Object.transform.position, Object.transform.rotation);
}
}
}
/*
GameControl:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameControl : MonoBehaviour
{
public Text pointsTextUI;
private int Points;
public Text LiveTextUI;
public int Live;
void Start()
{
string formatTextStart = string.Format("{0:00000000}", Points);
pointsTextUI.text = formatTextStart;
string LiveTextStart = string.Format("3", Live);
LiveTextUI.text = LiveTextStart;
}
public void AddPoints(int NewPoints)
{
Points += NewPoints;
UpdateScore();
}
void UpdateScore()
{
string formatText = string.Format("{0:00000000}", Points);
pointsTextUI.text = formatText;
}
public void RemoveLives(int LessLife)
{
Live--;
Lives();
}
public void Lives()
{
string formatTextLive = string.Format("0", Live);
LiveTextUI.text = formatTextLive;
}
}
*/