1
0
Fork 0
Bildschirmflausch-LD41/Assets/Scripts/Bullet.cs
Saibotk 83e54fb772 Entity uses Attack
Player shoots bullets
2018-04-22 23:50:39 +02:00

46 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;
}
void OnCollisionEnter2D(Collision2D collision) {
if ( owner == null )
return;
Debug.Log("Collided");
if ( collision.collider.gameObject.tag != owner.tag ) {
Debug.Log("calc");
Mob m = collision.collider.gameObject.GetComponent(typeof(Mob)) as Mob;
if (m != null) {
m.InflictDamage(damage);
}
Destroy(this.gameObject);
}
}
}