Skip to content

Instantly share code, notes, and snippets.

@JonathanYin
Last active July 20, 2017 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathanYin/a2bc1c307a03d4ed7cca8c31835b22b2 to your computer and use it in GitHub Desktop.
Save JonathanYin/a2bc1c307a03d4ed7cca8c31835b22b2 to your computer and use it in GitHub Desktop.
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);
}
}
}
@JonathanYin
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment