using System.Collections; using System.Collections.Generic; using UnityEngine; public class BullitMove : MonoBehaviour { public float moveSpeed = 5; public float desTime = 10f; public string playerID; public GameObject effectPrefab; float currShowTime = 0f; Vector3 vector3_startPosition; public bool isTriggerFirst=true; // Start is called before the first frame update void Awake() { Init(); Destroy(gameObject, desTime); } /// /// 对象池用 /// public void Init() { vector3_startPosition = transform.position; } // Update is called once per frame void Update() { //方便帧同步 currShowTime += Time.deltaTime; Vector3 targetPoint = transform.up.normalized * currShowTime * moveSpeed; transform.position = vector3_startPosition + targetPoint; } public void OnTriggerEnter2D(Collider2D collision) { if (isTriggerFirst) { if (collision.tag == "Monster") { isTriggerFirst=false; //击中特效 Instantiate(effectPrefab,transform.position,Quaternion.identity); //受激 collision.transform.GetComponent().monsterData.charactersHealth.OnHurt(10, CharacterHurtType.none); Destroy(collision.gameObject); Destroy(gameObject); } } } }