Commit 781857a8 authored by tmorga18's avatar tmorga18

Merged the fireball and watershield actions into one script

parent 0b883507
fileFormatVersion: 2
guid: 20fb6f28ca90a4a9492d76f7f0042220
timeCreated: 1478844848
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: afa3b25f0de7541cb9c01e694f6778e1
timeCreated: 1477008989
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
...@@ -4,34 +4,24 @@ using UnityEngine.UI; ...@@ -4,34 +4,24 @@ using UnityEngine.UI;
public class Actions : MonoBehaviour { public class Actions : MonoBehaviour {
// The array full of the character's abilities public GameObject[] abilities = new GameObject[4]; // The array full of the character's abilities
public GameObject[] abilities = new GameObject[4]; public GameObject currentAbility = null; // Which ability is currently active
private int abilitiesCounter = 0; // A counter which lets you cycle through the abilities
public Image abilitiesImage; // Picture which shows which ability it active
// *** Choose Ability *** private Color abilityUnusable;
// Which ability is currently active private Color abilityUsable;
public GameObject currentAbility = null;
// A counter which lets you cycle through the abilities
public int abilitiesCounter = 0;
// Picture which shows which ability it active
public Image abilitiesImage;
// *** RotateAbilities *** public int fireballSpeed = 5;
// The axis around which the abilities rotate
private Vector3 zAxis = new Vector3(0, 0, 1);
// The point around which the abilities rotate
public GameObject center;
public GameObject waterShieldPrefab;
public bool waterShieldUsable = true; public bool waterShieldUsable = true;
private float waterShieldTimer = 0.0f; private float waterShieldTimer = 0.0f;
public float waterShieldCooldown = 5.0f; public float waterShieldCooldown = 5.0f;
private Color abilityUnusable;
private Color abilityUsable;
private Vector3 LastInput;
void Start () { void Start () {
// Set the initial ability to something so that it's not null // Set the initial ability to something so that it's not null
CycleAbility(); CycleAbility();
...@@ -43,6 +33,12 @@ public class Actions : MonoBehaviour { ...@@ -43,6 +33,12 @@ public class Actions : MonoBehaviour {
void Update () { void Update () {
RaycastHit2D hit = Physics2D.Raycast(transform.position, GetLastDirection());
Debug.DrawRay(transform.position, GetLastDirection(), Color.red);
// Constantly check where the player is facing
GetLastDirection();
if(Input.GetButtonDown("Fire1")) { if(Input.GetButtonDown("Fire1")) {
UseAbility(currentAbility.name); UseAbility(currentAbility.name);
} }
...@@ -61,15 +57,12 @@ public class Actions : MonoBehaviour { ...@@ -61,15 +57,12 @@ public class Actions : MonoBehaviour {
// If the player presses the button to choose an ability... // If the player presses the button to choose an ability...
if(Input.GetButtonDown("Fire2")) { if(Input.GetButtonDown("Fire2")) {
// Increment the counter // Increment the counter
abilitiesCounter++; abilitiesCounter++;
// Call the ChooseAbility() function // Call the ChooseAbility() function
CycleAbility(); CycleAbility();
// A loop which will rotate each of the abilities in the array
foreach(GameObject ability in abilities) {
StartCoroutine(RotateAbility(ability));
}
} }
} }
...@@ -81,51 +74,59 @@ public class Actions : MonoBehaviour { ...@@ -81,51 +74,59 @@ public class Actions : MonoBehaviour {
if(abilitiesCounter > abilities.Length - 1) { if(abilitiesCounter > abilities.Length - 1) {
abilitiesCounter = 0; abilitiesCounter = 0;
} }
// Set the currentAbility to the one chosen by the abilitiesCounter // Set the currentAbility to the one chosen by the abilitiesCounter
currentAbility = abilities[abilitiesCounter]; currentAbility = abilities[abilitiesCounter];
// Set the image of the gameObject of the ability equal to the picture of the currentAbility // Set the image of the gameObject of the ability equal to the picture of the currentAbility
abilitiesImage.GetComponent<Image>().sprite = currentAbility.GetComponent<SpriteRenderer>().sprite; abilitiesImage.GetComponent<Image>().sprite = currentAbility.GetComponent<SpriteRenderer>().sprite;
} }
IEnumerator RotateAbility(GameObject ability) {
// Initially set the rotationCounter to 0
float rotationCounter = 0;
// This loop will rotate each element around a center pivot point
while(rotationCounter <= 8) {
ability.transform.RotateAround(center.transform.position, zAxis, 10f);
rotationCounter++;
yield return new WaitForSeconds(0.000000001f);
}
}
public void UseAbility(string myCurrentAbility) { public void UseAbility(string myCurrentAbility) {
Debug.Log(myCurrentAbility);
switch(myCurrentAbility) { switch(myCurrentAbility) {
case "Fireball": case "Ability - Fireball":
Debug.Log("Casting fireball!"); GameObject clone = Instantiate (currentAbility, this.transform.position, Quaternion.identity) as GameObject;
clone.GetComponent<FireballProjectile>().move = LastInput;
clone.GetComponent<FireballProjectile>().speed = fireballSpeed;
break; break;
case "Water Shield":
case "Ability - Water Shield":
if(waterShieldUsable == true) { if(waterShieldUsable == true) {
GameObject myShield = (GameObject)Instantiate(waterShieldPrefab, transform.position, Quaternion.identity); GameObject myShield = (GameObject)Instantiate(currentAbility, transform.position, Quaternion.identity);
WaterShield waterShield = myShield.GetComponent<WaterShield>(); WaterShield waterShield = myShield.GetComponent<WaterShield>();
waterShield.mainCharacter = this.gameObject.transform;
waterShieldUsable = false; waterShieldUsable = false;
} }
break; break;
case "Rock":
case "Ability - Rock":
Debug.Log("Throwing a rock!"); Debug.Log("Throwing a rock!");
break; break;
case "Breath of Air":
case "Ability - Breath of Air":
Debug.Log("Casting breath of air!"); Debug.Log("Casting breath of air!");
break; break;
} }
} }
public Vector3 GetLastDirection() {
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);
}
return LastInput;
}
} }
fileFormatVersion: 2
guid: aa31553023d864160985ca0e82b9ae15
timeCreated: 1478832493
licenseType: Free
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
cubemapConvolution: 0
cubemapConvolutionSteps: 7
cubemapConvolutionExponent: 1.5
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: 16
mipBias: -1
wrapMode: 1
nPOTScale: 0
lightmap: 0
rGBM: 0
compressionQuality: 50
allowsAlphaSplitting: 0
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 10
alphaIsTransparency: 1
textureType: 8
buildTargetSettings: []
spriteSheet:
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
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