// Update is called once per frame void Update() { if (target != null) { transform.LookAt(transform.position); transform.position += transform.forward * speed * Time.deltaTime; if (Vector3.Distance(target.transform.position, transform.position) < 1.0F) { Debug.Log("击中" + target.creatureName); GameObject obj = Global.GetPrefab("FireBoltHit"); //Resources.Load("FireBoltHit") as GameObject; if (obj != null) { GameObject hitEffect = Instantiate(obj, transform.position, transform.rotation) as GameObject; } BeDamageEvtArg arg = new BeDamageEvtArg(); arg.srcUnitID = caster.GetInstanceID(); arg.descUnitID = target.GetInstanceID(); arg.value = caster.intelligence * 10 + 100; FireEvent(this, EventType.EVT_BE_DAMAGED, arg); Destroy(gameObject); } } else { Destroy(gameObject); } }
public void OnBeDamaged(object sender, EventArgs arg) { BeDamageEvtArg e = arg as BeDamageEvtArg; if (GetInstanceID() != e.descUnitID) { return; } life -= e.value; GameObject obj = EditorUtility.InstanceIDToObject(e.srcUnitID) as GameObject; string attackName = ""; if (obj) { attackName = obj.name; } //Debug.Log ("遭受到来自"+attackName+"的"+e.value+"点伤害"); Global.Println("遭受到来自" + attackName + "的" + e.value + "点伤害"); if (life <= 0) { UnitDieEvtArg ueArg = new UnitDieEvtArg(); ueArg.deadUnitID = GetInstanceID(); ueArg.murdererID = e.srcUnitID; ueArg.deadUnit = this.gameObject.GetComponent <Actor> (); if (obj != null) { ueArg.killerUnit = obj.gameObject.GetComponent <Actor> (); } FireEvent(this, EventType.EVT_UNIT_DIE, ueArg); } }
public void endAttack() { //Debug.LogWarning (creatureName + "攻击完成"); BeDamageEvtArg arg = new BeDamageEvtArg(); arg.srcUnitID = transform.GetInstanceID(); if (targetUnit) { arg.srcUnitID = GetInstanceID(); arg.descUnitID = targetUnit.GetComponent <Actor>().GetInstanceID(); arg.value = baseAttackDamage * (1 + strength * 0.02F); FireEvent(this, EventType.EVT_BE_DAMAGED, arg); } }