Commit 5ab16613 authored by Jordan McKenney's avatar Jordan McKenney

Added a fireball prefab and script to spawn fireballs

parent b75c40b0
fileFormatVersion: 2
guid: 6d6525803f9c2de4e8233fc51322fdc5
guid: 3fd9c01e8800fc54681146f720a0d04b
folderAsset: yes
timeCreated: 1476403153
timeCreated: 1477008945
licenseType: Free
DefaultImporter:
userData:
......
......@@ -4,26 +4,22 @@ using System.Collections;
public class FireballMove : MonoBehaviour {
public float speed;
private Rigidbody2D fireRB;
public int direction;
public Vector2 move;
// Use this for initialization
void Start () {
fireRB = GetComponent<Rigidbody2D> ();
/*
if (direction == 0)
move = new Vector2 (1,0);
if (direction == 1)
move = new Vector2 (0,1);
if (direction == 2)
move = new Vector2 (-1,0);
if (direction == 3)
move = new Vector2 (0,-1);
*/
fireRB.velocity = (move * speed);
}
// Update is called once per frame
void Update () {
fireRB.MovePosition((Vector2)transform.position + move*speed);
//fireRB.MovePosition((Vector2)transform.position + move*speed);
}
void OnCollisionEnter2D(Collision2D c){
Destroy (this.gameObject);
}
}
......@@ -4,12 +4,14 @@ using System.Collections;
public class HeroAttackController : MonoBehaviour {
enum ability {fireball, water, others };
public int direction;
private int direction;
public float speed;
private ability currentAbility = ability.fireball;
public GameObject FireballPrefab;
private Vector3 LastInput = new Vector3 (0, 1, 0);
// Use this for initialization
void Start () {
......@@ -17,16 +19,29 @@ public class HeroAttackController : MonoBehaviour {
// Update is called once per frame
void Update(){
if (Input.GetButtonDown("Fire1")){
Vector3 input = new Vector3 (Input.GetAxisRaw ("Horizontal"), Input.GetAxisRaw ("Vertical"), 0);
if (input.x == 0 && input.y == 0) {
//do nothing
} else if (input.y != 0) {
LastInput = new Vector3 (0, input.y, 0);
} else {
LastInput = new Vector3 (input.x, 0, 0);
}
if (Input.GetButtonDown("Fire1")){
switch (currentAbility)
{
case ability.fireball:
GameObject clone = Instantiate (FireballPrefab, new Vector3 (0, 0, 0), Quaternion.identity) as GameObject;
clone.GetComponent<FireballMove> ().move = GetComponent<PlayerAnimation> ().lastInput;
clone.GetComponent<FireballMove> ().speed = speed;
Vector3 pos = GetComponent<Transform> ().position;
GameObject clone = Instantiate (FireballPrefab, pos, Quaternion.identity) as GameObject;
clone.GetComponent<FireballMove>().move = LastInput;
clone.GetComponent<FireballMove>().speed = speed;
Debug.Log("fireball");
break;
Debug.Log("fireball");
break;
default:
Debug.Log("default");
break;
......@@ -37,6 +52,9 @@ public class HeroAttackController : MonoBehaviour {
Debug.Log("melee");
}
}
public Vector3 GetLastDirection4(){
return LastInput;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment