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

Added a fireball prefab and script to spawn fireballs

parent b75c40b0
fileFormatVersion: 2 fileFormatVersion: 2
guid: 6d6525803f9c2de4e8233fc51322fdc5 guid: 3fd9c01e8800fc54681146f720a0d04b
folderAsset: yes folderAsset: yes
timeCreated: 1476403153 timeCreated: 1477008945
licenseType: Free licenseType: Free
DefaultImporter: DefaultImporter:
userData: userData:
......
...@@ -4,26 +4,22 @@ using System.Collections; ...@@ -4,26 +4,22 @@ using System.Collections;
public class FireballMove : MonoBehaviour { public class FireballMove : MonoBehaviour {
public float speed; public float speed;
private Rigidbody2D fireRB; private Rigidbody2D fireRB;
public int direction;
public Vector2 move; public Vector2 move;
// Use this for initialization // Use this for initialization
void Start () { void Start () {
fireRB = GetComponent<Rigidbody2D> (); fireRB = GetComponent<Rigidbody2D> ();
/* fireRB.velocity = (move * speed);
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);
*/
} }
// Update is called once per frame // Update is called once per frame
void Update () { 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; ...@@ -4,12 +4,14 @@ using System.Collections;
public class HeroAttackController : MonoBehaviour { public class HeroAttackController : MonoBehaviour {
enum ability {fireball, water, others }; enum ability {fireball, water, others };
public int direction; private int direction;
public float speed; public float speed;
private ability currentAbility = ability.fireball; private ability currentAbility = ability.fireball;
public GameObject FireballPrefab; public GameObject FireballPrefab;
private Vector3 LastInput = new Vector3 (0, 1, 0);
// Use this for initialization // Use this for initialization
void Start () { void Start () {
...@@ -17,16 +19,29 @@ public class HeroAttackController : MonoBehaviour { ...@@ -17,16 +19,29 @@ public class HeroAttackController : MonoBehaviour {
// Update is called once per frame // Update is called once per frame
void Update(){ 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) switch (currentAbility)
{ {
case ability.fireball: case ability.fireball:
GameObject clone = Instantiate (FireballPrefab, new Vector3 (0, 0, 0), Quaternion.identity) as GameObject; Vector3 pos = GetComponent<Transform> ().position;
clone.GetComponent<FireballMove> ().move = GetComponent<PlayerAnimation> ().lastInput;
clone.GetComponent<FireballMove> ().speed = speed; GameObject clone = Instantiate (FireballPrefab, pos, Quaternion.identity) as GameObject;
clone.GetComponent<FireballMove>().move = LastInput;
clone.GetComponent<FireballMove>().speed = speed;
Debug.Log("fireball"); Debug.Log("fireball");
break; break;
default: default:
Debug.Log("default"); Debug.Log("default");
break; break;
...@@ -37,6 +52,9 @@ public class HeroAttackController : MonoBehaviour { ...@@ -37,6 +52,9 @@ public class HeroAttackController : MonoBehaviour {
Debug.Log("melee"); 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