2018-04-22 23:49:43 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace Assets.Scripts.Entities.Attack {
|
|
|
|
|
class SingleShot : IAttack {
|
|
|
|
|
|
2018-04-23 18:38:43 +02:00
|
|
|
|
protected int damage = 12;
|
|
|
|
|
protected float cooldown = 1;
|
|
|
|
|
protected int range = 4;
|
|
|
|
|
protected float speed = 10;
|
2018-04-22 23:49:43 +02:00
|
|
|
|
GameObject owner;
|
|
|
|
|
GameObject bulletPrefab;
|
|
|
|
|
Transform spawn;
|
|
|
|
|
|
|
|
|
|
public SingleShot(GameObject owner) {
|
|
|
|
|
this.owner = owner;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-23 20:19:12 +02:00
|
|
|
|
public void SetCooldown(float cd) {
|
|
|
|
|
cooldown = cd;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-22 23:49:43 +02:00
|
|
|
|
public void SetSpawn(Transform t) {
|
|
|
|
|
spawn = t;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetPrefab(GameObject bullet) {
|
|
|
|
|
this.bulletPrefab = bullet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Attack() {
|
2018-04-23 19:50:04 +02:00
|
|
|
|
if ( bulletPrefab == null ) {
|
|
|
|
|
Debug.Log("SingleShot: No Prefab defined for Bullet!");
|
2018-04-22 23:49:43 +02:00
|
|
|
|
return;
|
2018-04-23 19:50:04 +02:00
|
|
|
|
}
|
2018-04-23 18:52:21 +02:00
|
|
|
|
GameObject b = UnityEngine.Object.Instantiate(bulletPrefab);
|
2018-04-22 23:49:43 +02:00
|
|
|
|
b.transform.rotation = spawn.rotation;
|
|
|
|
|
b.transform.position = spawn.position;
|
|
|
|
|
Bullet bu = b.GetComponent<Bullet>();
|
|
|
|
|
bu.SetDamage(damage);
|
2018-04-23 18:38:43 +02:00
|
|
|
|
bu.SetSpeed(speed);
|
2018-04-22 23:49:43 +02:00
|
|
|
|
bu.SetOwner(owner);
|
2018-04-23 18:52:21 +02:00
|
|
|
|
GameController.instance.GetAudioControl().SfxPlay(AudioControl.Sfx.shoot);
|
2018-04-22 23:49:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float GetCooldownTime() {
|
|
|
|
|
return cooldown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float GetRange() {
|
|
|
|
|
return range;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|