Hello! I have been creating two spells but now have I tried and search how I could make this better.
I feel this is not good that I have been doing.
My goal is to create spells that I can drag later to my action bars. How could i improved and make this easier for me? Should I use List?
Here do I add my spells right now.
public class PlayerSpells : MonoBehaviour
{
private bool castSpell;
private float distance = 8f;
void Update ()
{
if (Input.GetKeyDown (KeyCode.Alpha1))
{
Fireball ();
}
if (Input.GetKeyDown (KeyCode.Alpha2))
{
Iceball ();
}
}
public void Fireball()
{
if (Player.opponent != null && Vector3.Distance (transform.position, Player.opponent.transform.position) < distance)
{
if (PlayerMovement.agent.velocity.magnitude < 0.5f)
{
Instantiate (Resources.Load ("FireballProjectile"), transform.position, transform.rotation);
castSpell = true;
}
else
{
castSpell = false;
}
}
}
public void Iceball()
{
if (Player.opponent != null && Vector3.Distance (transform.position, Player.opponent.transform.position) < distance)
{
Instantiate (Resources.Load ("IceballProjectile"), transform.position, transform.rotation);
}
}
}
Here is my Fireball script exemple.
public class Fireball : MonoBehaviour
{
public int fireDamage;
public float speed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
transform.Translate (Vector3.forward * speed * Time.deltaTime);
}
void OnTriggerEnter(Collider other)
{
if (Player.opponent != null && other.tag == "Enemy")
{
Player.opponent.GetComponent<Enemy> ().GetHit (fireDamage);
}
}
}