51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
public class PlayerArrow : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
private float damage;
|
|||
|
|
private float speed;
|
|||
|
|
private float range;
|
|||
|
|
private Vector3 startPos;
|
|||
|
|
private bool isFired = false;
|
|||
|
|
|
|||
|
|
public void Initialize(float dmg, float arrowSpeed, float maxRange)
|
|||
|
|
{
|
|||
|
|
this.damage = dmg;
|
|||
|
|
this.speed = arrowSpeed;
|
|||
|
|
this.range = maxRange;
|
|||
|
|
this.startPos = transform.position;
|
|||
|
|
this.isFired = true;
|
|||
|
|
|
|||
|
|
Rigidbody rb = GetComponent<Rigidbody>();
|
|||
|
|
if (rb != null)
|
|||
|
|
{
|
|||
|
|
rb.useGravity = false; // <20><><EFBFBD><EFBFBD> <20><EFBFBD>
|
|||
|
|
rb.velocity = transform.forward * speed;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Destroy(gameObject, 5f); // 5<><35> <20><> <20>ڵ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void Update()
|
|||
|
|
{
|
|||
|
|
if (!isFired) return;
|
|||
|
|
if (Vector3.Distance(startPos, transform.position) >= range)
|
|||
|
|
{
|
|||
|
|
Destroy(gameObject);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void OnTriggerEnter(Collider other)
|
|||
|
|
{
|
|||
|
|
if (other.CompareTag("Enemy"))
|
|||
|
|
{
|
|||
|
|
var monster = other.GetComponent<MonsterClass>();
|
|||
|
|
if (monster != null) monster.TakeDamage(damage);
|
|||
|
|
Destroy(gameObject);
|
|||
|
|
}
|
|||
|
|
else if (other.CompareTag("Wall") || other.CompareTag("Ground"))
|
|||
|
|
{
|
|||
|
|
Destroy(gameObject);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|