Last active
July 20, 2017 17:14
-
-
Save JonathanYin/909d5034fde2ff5c14e4e03d2f14fcd9 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; | |
public class MoveScript : MonoBehaviour | |
{ | |
public Vector2 speed = new Vector2(10, 10); | |
public Vector2 direction = new Vector2(-1, 0); | |
private Vector2 movement; | |
private Rigidbody2D rigidbodyComponent; | |
public static int lives = 3; | |
void Update() | |
{ | |
// 2 - Movement | |
movement = new Vector2( | |
speed.x * direction.x, | |
speed.y * direction.y); | |
} | |
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; | |
//other.gameObject.SetActive(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); | |
} | |
else if (other.tag == "Player2") | |
{ | |
//other.GetComponent<Renderer>().enabled = false; | |
//other.gameObject.SetActive(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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script is attached to an Enemy in the game, which is spawned from a BombSpawner and moves at a consistent pace across the screen. If a player collides with it, the player is killed.