Last active
July 20, 2017 17:14
-
-
Save JonathanYin/a2bc1c307a03d4ed7cca8c31835b22b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class SpikeBall : MonoBehaviour | |
{ | |
//a holder for our Animator | |
Animator anim; | |
//a public float for the explosion radius | |
private Vector2 movement; | |
private Rigidbody2D rigidbodyComponent; | |
GameObject objToSpawn; | |
// Use this for initialization | |
public Collider2D[] colliders; | |
public static int lives = 3; | |
void Start() | |
{ | |
anim = GetComponent<Animator>(); | |
} | |
void FixedUpdate() | |
{ | |
if (rigidbodyComponent == null) rigidbodyComponent = GetComponent<Rigidbody2D>(); | |
// Apply movement to the rigidbody | |
rigidbodyComponent.velocity = movement; | |
} | |
void OnTriggerEnter2D(Collider2D other) | |
{ | |
if (other.tag == "Player1") | |
{ | |
//other.GetComponent<Renderer>().enabled = false; | |
/*if (Global.count <= 0) | |
{ | |
Destroy(other.gameObject); | |
} | |
else | |
{ | |
Global.count = Global.count - 1; | |
Global.DisplayHearts(); | |
}*/ | |
SpecialEffectsHelper.Instance.Explosion(transform.position); //EXPLOSION!!! | |
Destroy(other.gameObject); | |
//other.gameObject.SetActive(false); | |
} | |
else if (other.tag == "Player2") | |
{ | |
//other.GetComponent<Renderer>().enabled = false; | |
/*if (Global.count <= 0) | |
{ | |
Destroy(other.gameObject); | |
} | |
else | |
{ | |
Global.count = Global.count - 1; | |
Global.DisplayHearts(); | |
}*/ | |
SpecialEffectsHelper.Instance.Explosion(transform.position); //EXPLOSION!!! | |
Destroy(other.gameObject); | |
/*if (lives <= 0) | |
{ | |
Destroy(other.gameObject); | |
lives = lives - 1; | |
}*/ | |
//other.gameObject.SetActive(false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This simple script, which is attached to a SpikeBall object, allows the object to destroy players upon collision. In my settings, I have increased the gravity scale so that it falls at a very high speed, adding greater difficulty to the game.