61 lines
1.5 KiB
C#
61 lines
1.5 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
public class bullet : MonoBehaviour
|
|||
|
{
|
|||
|
[Header("<22><><EFBFBD>е<EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>㣬<EFBFBD><E3A3AC><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>")]
|
|||
|
public GameObject tagpos;
|
|||
|
[Header("<22><><EFBFBD>е<EFBFBD><D0B5>ٶȣ<D9B6><C8A3><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>")]
|
|||
|
public float speed;
|
|||
|
[Header("<22>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD>˺<EFBFBD>,<2C><><EFBFBD>Ը<EFBFBD><D4B8><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD>50")]
|
|||
|
public float changehp=50;
|
|||
|
// Start is called before the first frame update
|
|||
|
void Update()
|
|||
|
{
|
|||
|
if (tagpos != null)
|
|||
|
{
|
|||
|
move();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Destroy(gameObject); // <20><><EFBFBD><EFBFBD>Ŀ<EFBFBD>겻<EFBFBD><EAB2BB><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void Init(GameObject target, float bulletSpeed,float changehp=50)
|
|||
|
{
|
|||
|
this.tagpos = target;
|
|||
|
this.speed = bulletSpeed;
|
|||
|
this.changehp = changehp;
|
|||
|
}
|
|||
|
|
|||
|
void move()
|
|||
|
{
|
|||
|
// <20>ӵ<EFBFBD><D3B5><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD>ƶ<EFBFBD>
|
|||
|
Vector3 direction = (tagpos.transform.position - transform.position).normalized;
|
|||
|
transform.position += direction * speed * Time.deltaTime;
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5>dz<EFBFBD><C7B3>ӽ<EFBFBD>Ŀ<EFBFBD>꣬<EFBFBD><EAA3AC>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
|
|||
|
if (Vector3.Distance(transform.position, tagpos.transform.position) < 0.1f)
|
|||
|
{
|
|||
|
HitTarget();
|
|||
|
}
|
|||
|
}
|
|||
|
// <20>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>
|
|||
|
private void HitTarget()
|
|||
|
{
|
|||
|
// <20><><EFBFBD>õ<EFBFBD><C3B5>˵<EFBFBD> changehp <20><><EFBFBD><EFBFBD>
|
|||
|
npcInfo enemy = tagpos.GetComponent<npcInfo>();
|
|||
|
if (enemy != null)
|
|||
|
{
|
|||
|
enemy.ChangeHp(-changehp); // <20><><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD>10<31><30><EFBFBD>˺<EFBFBD>
|
|||
|
Debug.Log("<22><><EFBFBD>е<EFBFBD><D0B5><EFBFBD>");
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>
|
|||
|
Destroy(gameObject);
|
|||
|
}
|
|||
|
|
|||
|
}
|