Skip to content
Permalink
4365931443
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
73 lines (53 sloc) 1.53 KB
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class DestroyByContact : MonoBehaviour
{
public GameObject explosion;
public GameObject playerExplosion;
public int scoreValue;
private GameController gameController;
public int health;
public GameObject Player;
void Start()
{
GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
if (gameControllerObject !=null)
{
gameController = gameControllerObject.GetComponent<GameController>();
}
if (gameController ==null)
{
Debug.Log("Cannot find GameController script");
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (!this.CompareTag("Player"))
{
if (other.CompareTag("Boundary") || other.CompareTag("Enemy"))
{
return;
}
}
gameController.AddScore(scoreValue);
if (!other.CompareTag("Player"))
{
Destroy(other.gameObject);
}
health--;
if (health <= 0)
{
if (this.tag == "Player")
{
Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
gameController.GameOver();
}
if (explosion != null)
{
Instantiate(explosion, transform.position, transform.rotation);
}
Destroy(gameObject);
}
}
}