public override void PickUp(RoleAttributes who) { isOccupied = true; Vector3 pos = new Vector3(who.transform.position.x, who.transform.position.y + transform.position.y, who.transform.position.z); transform.position = pos; }
private void OnCollisionEnter(Collision collision) { if (isOccupied.Equals(false)) { return; } if (collision.gameObject.tag.Equals("GameController")) { return; } Debug.Log(collision.gameObject.tag.Equals("GameController")); isOccupied = false; RoleAttributes roleAttributes = null; roleAttributes = collision.gameObject.GetComponent <RoleAttributes>(); if (roleAttributes != null) { roleAttributes.Injured(100); } hp -= 50; if (hp <= 0) { GameObject.Destroy(this.gameObject); } }
public override void Use(RoleAttributes who) { if (rigid == null) { rigid = this.GetComponent <Rigidbody>(); } Vector3 force = who.transform.localEulerAngles * 25; rigid.AddForce(force); Debug.Log("扔出去啦,力度:" + force); }
//2.至少两种形式的距离攻击,其中一种必须涉及使用岩石作为射弹,其中一种必须涉及使用板条箱。所有的弹丸如果击中玩家就会消失;没有击中玩家的石头是可重复使用的,但板条箱会被任何使用破坏。 private void AggressiveBehavior() { if (target == null) { return; //是否有攻击目标,目标是否在范围内 } float dis = Vector3.Distance(transform.position, target.transform.position); if (dis > vigilanceRange) { target = null; return; } Debug.Log(gameObject.name + "攻击目标:" + target); transform.LookAt(target.transform.position - transform.position); if (arms == null) //是否有物品 { Game_Material game_Material = null; Collider[] colliders = Physics.OverlapSphere(transform.position, vigilanceRange);//获取周围可用的物品 for (int index = 0; index < colliders.Length; index++) { game_Material = colliders[index].gameObject.GetComponent <Game_Material>(); if (game_Material != null && (!game_Material.IsOccupied())) { arms = game_Material; Debug.Log(gameObject.name + "——找到了武器:" + game_Material); arms.PickUp(this); //捡起 EndBehavior(); return; } } Debug.Log("没有攻击物品:" + colliders.Length); EndBehavior(); return; } Debug.Log("攻击物品成功扔出"); arms.Use(this); //捡岩石攻击 or //拿起板条箱攻击 arms = null; EndBehavior(); }
private void BehavioralDecision() //行为决定 { if (!isFree) { return; } Collider[] colliders = Physics.OverlapSphere(transform.position, vigilanceRange, layerMask); //获取周围(范围内)敌人 if (colliders.Length > 0) // { RoleAttributes roleAttributes = null; for (int index = 0; index < colliders.Length; index++) { roleAttributes = colliders[index].GetComponent <RoleAttributes>(); if (roleAttributes != null) { target = roleAttributes; AggressiveBehavior(); return; } } } LdleBehavior(); //没有敌人,进入休闲状态 }
} //捡起 public virtual void Use(RoleAttributes who) { } //使用
public virtual void PickUp(RoleAttributes who) { } //捡起