1
0
Fork 0

Attack package

2 simple attack types 
IAttack interface
This commit is contained in:
Saibotk 2018-04-22 23:49:43 +02:00
parent 75917b6e17
commit f03c0f4469
7 changed files with 131 additions and 0 deletions

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ad806e075b6034b4c9ceb3ae832ac6a3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,7 @@
namespace Assets.Scripts.Entities.Attack {
public interface IAttack {
void Attack();
float GetRange();
float GetCooldownTime();
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 58fd06520c77b6e4683cbf37114a3062
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,35 @@
using System;
using UnityEngine;
namespace Assets.Scripts.Entities.Attack {
[Serializable]
class MeleeAttack : IAttack {
int damage = 12;
float cooldown = 1;
float range = 1.5f;
GameObject owner;
public MeleeAttack(GameObject owner) {
this.owner = owner;
}
public void Attack() {
RaycastHit2D hit = Physics2D.Raycast(owner.transform.position, owner.transform.localRotation * Vector3.up, range);
Mob m = hit.collider.gameObject.GetComponent(typeof(Mob)) as Mob;
if ( m != null && m.tag != owner.tag) {
m.InflictDamage(damage);
}
// Todo animation?
}
public float GetCooldownTime() {
return cooldown;
}
public float GetRange() {
return range;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6320d45b19b0dac4d829864e5cc9e6d9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Assets.Scripts.Entities.Attack {
class SingleShot : IAttack {
int damage = 12;
float cooldown = 1;
int range = 4;
GameObject owner;
GameObject bulletPrefab;
Transform spawn;
public SingleShot(GameObject owner) {
this.owner = owner;
}
public void SetSpawn(Transform t) {
spawn = t;
}
public void SetPrefab(GameObject bullet) {
this.bulletPrefab = bullet;
}
public void Attack() {
if ( bulletPrefab == null )
return;
Debug.Log("Instantiate Bullet");
GameObject b = GameObject.Instantiate(bulletPrefab);
b.transform.rotation = spawn.rotation;
b.transform.position = spawn.position;
Bullet bu = b.GetComponent<Bullet>();
bu.SetDamage(damage);
bu.SetOwner(owner);
}
public float GetCooldownTime() {
return cooldown;
}
public float GetRange() {
return range;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 49a9496d02160ac448645af09ce8540f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: