public override State Update() { IceSlimeAI iceSlimeAI = (IceSlimeAI)GetAI(); IceSlime iceSlime = (IceSlime)iceSlimeAI.getCharacter(); GameObject myBody = iceSlime.GetGameObject(); float distance = Vector3.Distance(myBody.transform.position, iceSlime.currentTarget.transform.position); //如果有目标在视野内,则移动向目标,直到可以攻击到目标 if (distance < iceSlime.getAttr().getAttackRange()) { myBody.GetComponent <Rigidbody2D>().velocity = Vector3.zero; return(State.SUCESSED); } Room1 room = (Room1)myBody.GetComponentInParent(typeof(Room1)); float dx = myBody.transform.position.x; float dy = myBody.transform.position.y; if (dx >= room.transform.position.x + room.max_X || dx <= room.transform.position.x - room.max_X) { myBody.GetComponent <Rigidbody2D>().velocity = new Vector2(0, myBody.GetComponent <Rigidbody2D>().velocity.y); } if (dy >= room.transform.position.y + room.max_Y || dy <= room.transform.position.y - room.max_Y) { myBody.GetComponent <Rigidbody2D>().velocity = new Vector2(myBody.GetComponent <Rigidbody2D>().velocity.x, 0); } Vector3 dir = (iceSlime.currentTarget.transform.position - myBody.transform.position).normalized; myBody.GetComponent <Rigidbody2D>().velocity = dir * GetAI().getCharacter().getAttr().getSpeed() * Time.deltaTime; return(State.RUNNING); }
public override State Update() { IceSlimeAI iceSlimeAI = (IceSlimeAI)GetAI(); IceSlime iceSlime = (IceSlime)iceSlimeAI.getCharacter(); GameObject myBody = iceSlime.GetGameObject(); attackRange = iceSlime.getAttr().getAttackRange(); if (Vector3.Distance(myBody.transform.position, iceSlime.currentTarget.transform.position) < attackRange) { return(State.SUCESSED); } return(State.FAILED); }
//碰撞判定 void OnTriggerEnter2D(Collider2D collider) { IBullet bullet = collider.GetComponent <IBullet>(); if (bullet != null) { owner.UnderAttack(bullet.GetWeapon().GetOwner()); if (owner.getAttr().getHealth() <= 0) { Destroy(gameObject); } } }
public override void Enter() { base.Enter(); IceSlimeAI iceSlimeAI = (IceSlimeAI)GetAI(); IceSlime iceSlime = (IceSlime)iceSlimeAI.getCharacter(); GameObject myBody = iceSlime.GetGameObject(); ice = iceSlime.GetIce(); attackRate = iceSlime.getAttr().getAttackRate(); currentAttackRate = 0; currentRecoverTime = 0; isFire = false; currentDuring = fireDuring; count = 5; angle = Vector3.Angle(myBody.transform.up, (iceSlime.currentTarget.transform.position - myBody.transform.position).normalized); Vector3 cro = Vector3.Cross(myBody.transform.up, (iceSlime.currentTarget.transform.position - myBody.transform.position).normalized); angle *= Vector3.Dot(cro.normalized, myBody.transform.forward); }