1
0
Fork 0
Bildschirmflausch-LD41/Assets/Scripts/Bullet.cs
2018-04-22 23:59:13 +02:00

45 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour {
[SerializeField]
protected float speed = 1;
[SerializeField]
int damage = 0;
GameObject owner;
// Use this for initialization
void Start () {
}
public void SetDamage(int dmg) {
damage = dmg;
}
public void SetOwner(GameObject ow) {
owner = ow;
}
// Update is called once per frame
void Update () {
if ( owner == null )
return;
transform.position = transform.position + transform.localRotation * Vector3.up * speed * Time.deltaTime; // TODO do with physics (rigidbody)
}
void OnCollisionEnter2D(Collision2D collision) {
if ( owner == null )
return;
if ( collision.collider.gameObject.tag != owner.tag ) {
Mob m = collision.collider.gameObject.GetComponent(typeof(Mob)) as Mob;
if (m != null) {
m.InflictDamage(damage);
}
Destroy(this.gameObject);
}
}
}