using System.Collections; using System.Collections.Generic; using UnityEngine; //光剑 //砍中敌人时计算一段伤害,抽离敌人算第二段伤害 public class LightSword : MonoBehaviour { public int Damage_; public float Length; private bool grounded; private RaycastHit hit; public bool isAttacked; public GameObject Particle; private void Update() { Debug.DrawRay(gameObject.transform.position, gameObject.transform.forward * Length * 2, Color.red); grounded = Physics.Raycast(gameObject.transform.position, gameObject.transform.forward, out hit,Length * 2f); if (grounded && !isAttacked) { isAttacked = true; GameObject SwordEffect = Instantiate(Particle); SwordEffect.transform.position = hit.point + new Vector3(0f,0.1f,0f); if (hit.transform.tag == "hurtable") { Hurtable target = hit.transform.GetComponent(); target.hurt(Damage_); } } else if(!grounded && isAttacked) { isAttacked = false; } } }