bool shieldPressed; //盾牌 private void Awake() { sprintLeaf = Instantiate(sprintLeaf, transform.position, Quaternion.identity, transform); sprintLeaf.Stop(); blood = Instantiate(blood, transform.position, Quaternion.identity, transform); blood.Stop(); rigidbody = GetComponent <Rigidbody2D>(); anim = GetComponent <Animator>(); body = GetComponent <humanBody>(); if (body.tenetDirection == 0) //表示是逆转主角 ,此时寻找盾牌 { shield = gameObject.transform.Find("Shield").gameObject; Debug.Log("找到盾牌了"); shield.SetActive(false); //默认为不开启状态 shield.transform.parent = null; //将从属关系去掉,这样不会跟着旋转 } mController = GetComponent <MasterController>(); }
void Start_Now() { instance = this; Quaternion quatTiltAngle = new Quaternion(); quatTiltAngle.eulerAngles = new Vector3(-SensorAngle, 0.0f, 0.0f); kinectToWorld.SetTRS(new Vector3(0.0f, SensorHeight, 0.0f), quatTiltAngle, Vector3.one); AsyncCallback callback = null; callback = ar => { newIncomingEndPoint = remoteEPReceive; data = udpServerReceive.EndReceive(ar, ref newIncomingEndPoint); udpServerReceive.BeginReceive(callback, null); String json = Encoding.ASCII.GetString(data, 0, data.Length); if (json == String.Empty) { saveHuman = null; } else { saveHuman = JsonUtility.FromJson <humanBody>(json); } }; udpServerReceive.BeginReceive(callback, null); }
private void OnTriggerEnter2D(Collider2D collision) { //当在攻击时进行攻击判断 if (collision.gameObject.layer != father.gameObject.layer) //同类之间不会打到 { if (attacking == true) { Debug.Log("击中的是 " + collision); //设置死亡动画 humanBody body = collision.GetComponent <humanBody>(); // Debug.Log(col) //123 bool hit; //是否命中的判断 hit = AttackJudge(body, father.GetComponent <humanBody>()); if (hit == true) //表示命中,此时播放动画 { blood.Play(); Instantiate(crack, hitPoint.position, this.transform.rotation); } attacking = false; //crack.SetActive(true); // particle.Play(); //Destroy(particle, particle.main.duration); } } }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state //override public void onstateenter(animator animator, animatorstateinfo stateinfo, int layerindex) //{ //} public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { //改变移速 //Debug.Log(animator.gameObject.name); humanBody body = animator.gameObject.GetComponent <humanBody>(); //body.speed = body.attackSpeed; }
public static Vector2 Jump(humanBody body, int jumpHeight) { if (jumpHeight > 0) { return(body.Jumping(1, 0, new Vector2())); } //如果jumpHeight为0表示跳跃结束 return(new Vector2(0, 0)); }
//用于敌人检测周围的状况,这个游戏中只需要检测玩家即可 // Start is called before the first frame update void Start() { //transform.for body = GetComponent<humanBody>(); aiController = GetComponent<AIController>(); mController = GetComponent<MasterController>(); }
private CursorController cController; //保存鼠标变量 private void Awake() { cController = GetComponent <CursorController>(); body = GetComponent <humanBody>(); rigidbody = GetComponent <Rigidbody2D>(); anim = GetComponent <Animator>(); mController = GetComponent <MasterController>(); }
public static Vector2 Move(humanBody body, int direction, int speed) { //控制敌人的行走 if (direction == 1) { return(body.Walk(1, Vector2.zero)); } else { return(body.Walk(-1, Vector2.zero)); } }
public static void RandomAttack(humanBody body, int IQ) { //根据IQ的高低来决定攻击的频率 Random.Range(1, 2); //随机到数时才会攻击 if (Random.Range(1, 300 / IQ) == 1) { //此时攻击 AITool.Attack(body); } }
public static void EnemyFrozen(float speed) { //将不在同一维度的敌人冰封起来 for (int i = 0; i < Master.bodyCollector.Count; i++) { humanBody tempBody = Master.bodyCollector[i]; if (tempBody.GetComponent <AIController>() != null) //为敌人 { if (tempBody.tenetDirection == 0) { tempBody.GetAnimator().SetFloat("Speed", speed); } } } }
public static void CalculateStageEnemy() { //计算阶段敌人 // 正常时死亡的人数,当cd变为0时这个值变为固定值 for (int i = 0; i < Master.bodyCollector.Count; i++) { humanBody tempBody = Master.bodyCollector[i]; if (tempBody.tenetDirection == 1) { if (tempBody.GetAnimator().GetBool("dead") == true) { Master.stageKilliedNum++; } } } }
public static void IfLost(GameObject target, humanBody body, float lostDistance) { //检测当前目标与自身的距离,跳远则舍弃目标 if (target != null) { float dis = (target.transform.position - body.transform.position).magnitude; //看下当前的距离 if (dis > lostDistance) { //大于丢失距离,目标舍弃 target = null; Debug.Log("距离太远,目标丢失"); } //Debug.Log(dis); } }
public static Vector2 Patrol(GameObject target, humanBody body, AIController aiController, int speed) { //如果有巡逻点 并且无目标时进行巡逻操作 Vector2 position = new Vector2(0, 0); int size = aiController.patrolDot.Length; //记录巡逻点的个数 if (target == null && size > 0) //无目标且巡逻个数大于0 { //向这个巡逻点靠近 position += AITool.ApproachOrAway(aiController.patrolDot[aiController.patrolState], body, aiController.faceDistance, speed, 1); //Debug.Log("qwe"); //如果和巡逻点无限靠近了,则patrolstate++ float dis = (aiController.patrolDot[aiController.patrolState].transform.position - body.transform.position).magnitude; //Debug.Log(size-1); if (dis < 1) { int waitTime = aiController.patrolDot[aiController.patrolState].GetComponent <patrolDot>().waitTime; //获取巡逻节点的等待时间 if (aiController.timer < waitTime) { aiController.timer++; } else { if (aiController.patrolState < size - 1) { aiController.patrolState++; } else { //回到起点 aiController.patrolState = 0; } aiController.timer = 0; //计时器归零 } } } return(position); }
private void OnTriggerEnter2D(Collider2D collision) { //当碰到物体时,使用粒子效果,并且消失,如果碰到的是玩家的话(非自己),则进入伤害步骤 if (Master.status == 0) { if (collision.gameObject.tag != "JumpingBoard") { if (collision.gameObject != owner) { // Debug.Log("name " + owner); // Debug.Log("bullet "+ collision.gameObject.name); particle.Play(); //如果击中的是人或敌人 if (collision.gameObject.layer == LayerMask.NameToLayer("Player") || collision.gameObject.layer == LayerMask.NameToLayer("Enemy")) { //如果碰到的是玩家,则进入伤害判断 //gameObject.tag //设置死亡动画 humanBody body = collision.GetComponent <humanBody>(); swordBody.AttackJudge(body, this.owner.GetComponent <humanBody>()); // Debug.Log(col) //123 //body.Dead(0); } GetComponent <BoxCollider2D>().enabled = false; //修改子弹的z坐标为-3 //gameObject.SetActive(false); //暂时不进行运动 //Debug.Log("123"); humanBody.AddFrame(this.mController, Master.frame, ActionEnum.movement.bulletBack, transform.position, this.speed, 0, this.tenetDirection); transform.position = new Vector3(transform.position.x, transform.position.y, -10); speed = 0f; //Destroy(this.gameObject); } } } }
public static bool AttackJudge(humanBody targetBody, humanBody sourceBody) { //先判断是否已经死亡 //分为多种情况 //1.回放时,则如果是同纬度的人则不判断,非同纬度则倒退 //2.正常情况,正常死亡 //3.正常情况下,但是打到的不是同一纬度的人,则倒退 if (targetBody == null || sourceBody == null) { Debug.Log("body为null"); } //用于攻击后是否命中的判断 if (Master.status == 2 && targetBody.tenetDirection == sourceBody.tenetDirection) { Debug.Log("1"); } else if (Master.currentDirection != sourceBody.tenetDirection && targetBody.tenetDirection == sourceBody.tenetDirection) { //表示攻击者不在当前纬度且攻击到的目标和其一样不在当前纬度,则不进行判断 Debug.Log("2"); } else if (targetBody.tenetDirection != sourceBody.tenetDirection) //伤害判断前先判断是否在同一纬度,如果不在同一纬度则发生事件 { //此时为发生错误,需要让玩家自己进行倒退 Master.mistakeTimer = 40; //进行强制倒退 } else { Debug.Log("有死"); targetBody.Dead(0); return(true); } return(false); }
void Start_Now() { instance = this; Quaternion quatTiltAngle = new Quaternion(); quatTiltAngle.eulerAngles = new Vector3(-SensorAngle, 0.0f, 0.0f); kinectToWorld.SetTRS(new Vector3(0.0f, SensorHeight, 0.0f), quatTiltAngle, Vector3.one); AsyncCallback callback = null; callback = ar => { newIncomingEndPoint = remoteEP; data = udpServer.EndReceive(ar, ref newIncomingEndPoint); //udpClient.Send(data, data.Length, new IPEndPoint(IPAddress.Parse("192.168.1.5"), 12345)); udpServer.BeginReceive(callback, null); String json = Encoding.ASCII.GetString(data, 0, data.Length); if (json == String.Empty) { saveHuman = null; } else if (json == "a") { kill = true; } else if (json == "b") { bekilled = true; } else { saveHuman = JsonUtility.FromJson <humanBody>(json); } }; udpServer.BeginReceive(callback, null); }
public static void Attack(humanBody body) { body.Attack(body.direction, true, Vector2.zero); }
public void CalculateEnemy() { Master.totalEnemyNum = 0; //统计敌人 for (int i = 0; i < Master.bodyCollector.Count; i++) { humanBody tempBody = Master.bodyCollector[i]; if (tempBody.GetComponent <AIController>() != null) { //表示有AI控件,所以是敌人,此时totalNum++ if (Master.currentDirection == 1) { if (tempBody.tenetDirection == Master.currentDirection) //在正向时则被标记的反向敌人不算在敌人总数中 { Master.totalEnemyNum++; } } if (Master.currentDirection == 0) //反向时所有敌人都添加 { Master.totalEnemyNum++; } } } //进入逆转门后每个dead为true的敌人都可以加killedNum; Master.killedEnemyNum = 0; if (Master.currentDirection == 1) { //正常时死亡的人数,当cd变为0时这个值变为固定值 for (int i = 0; i < Master.bodyCollector.Count; i++) { humanBody tempBody = Master.bodyCollector[i]; if (tempBody.GetComponent <AIController>() != null) //为敌人 { if (tempBody.tenetDirection == 1) { if (tempBody.GetAnimator().GetBool("dead") == true) { Master.killedEnemyNum++; } } } } } if (Master.currentDirection == 0) { //逆转时死亡的人数 for (int i = 0; i < Master.bodyCollector.Count; i++) { humanBody tempBody = Master.bodyCollector[i]; if (tempBody.GetComponent <AIController>() != null) //为敌人 { if (tempBody.tenetDirection == 0) { if (tempBody.GetAnimator().GetBool("dead") == true) { Master.killedEnemyNum++; } } } } } Master.killedEnemyNum += Master.stageKilliedNum; //如果在逆转阶段则加上之前的数量 //Debug.Log(Master.killedEnemyNum + " " + Master.totalEnemyNum); }
private void FindTarget() { //if(this.target!=null) //Debug.Log(this.target); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //检测结果 RaycastHit hitInfo; Physics2D.queriesStartInColliders = false; //避免检测到自己 //Debug.Log(Camera.main.ScreenToWorldPoint(Input.mousePosition)); //Debug.DrawRay(Camera.main.ScreenToWorldPoint(Input.mousePosition), new Quaternion(0, 0, -1, 0) * gameObject.transform.up.normalized * 0.3f, Color.black); Debug.DrawRay(ray.origin, ray.direction * 50f, Color.black); //hits = Physics2D.RaycastAll(ray.origin,new Vector3(0,0,50),50f,1<<LayerMask.NameToLayer("Terrain")); Physics.Raycast(ray, out hitInfo, 200, 1 << LayerMask.NameToLayer("CursorCollider")); if (hitInfo.collider != null) { if (hitInfo.collider.gameObject.GetComponent <ChildCollider>() != null) { ChildCollider cCollider = hitInfo.collider.gameObject.GetComponent <ChildCollider>(); if (cCollider.father.GetComponent <Animator>().GetBool("dead") == false) //且不为死亡状态 { cCollider.SetKillCursor(); this.target = cCollider.father.GetComponent <humanBody>(); return; } } else { Debug.Log("判定失败"); } //Debug.Log(hitInfo); //Debug.Log(hit.collider.gameObject.name);//打印鼠标点击到的物体名称 //Debug.Log(LayerMask.NameToLayer("")); //Debug.Log("鼠标检测到敌人"); } //此时表示鼠标移出了物体,物体原有的预约图案变没 if (this.target != null && this.target.tenetDirection == 1) { //Debug.Log("改回来"); ChildCollider cCollider = this.target.gameObject.transform.Find("CursorCollider").GetComponent <ChildCollider>(); cCollider.SetDefaultCursor(); } this.target = null; }
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { //变回来 humanBody body = animator.gameObject.GetComponent <humanBody>(); // body.speed = body.normalSpeed; }
private void Awake() { body = GetComponent <humanBody>(); rigidbody = GetComponent <Rigidbody2D>(); }
public static Vector2 ApproachOrAway(GameObject target, humanBody body, float faceDistance, int speed, int e) { //e参数为1时表示靠近目标,为0时表示远离目标 Vector2 position = new Vector2(0, 0); float distance = 0; //根据目标的类型来决定要靠多近,如果是巡逻点则为0即可 //当有目标后靠近目标或者远离 if (target != null) { //靠近还是远离由这个参数决定 int leftX = 0; int rightX = 1; if (e == 1) { //靠近 leftX = 0; rightX = 1; } else if (e == 0) { //远离 leftX = 1; rightX = 0; } //如果是玩家,则要根据faceDirection来决定靠的距离 if (target.layer == LayerMask.NameToLayer("Player")) { //表示目标是玩家 distance = faceDistance; //Debug.Log("目标为玩家"); } //Debug.Log("正在调用"); //判断目标在左边还是右边来靠近 if (body.transform.position.x - target.transform.position.x >= 0.9 + distance) { // Debug.Log(body.transform.position.x - target.transform.position.x); //向左 position += AITool.Move(body, leftX, speed); } else if (target.transform.position.x - body.transform.position.x >= 0.9 + distance) { //Debug.Log(target.transform.position.x - body.transform.position.x); //向右 position += AITool.Move(body, rightX, speed); } else //表示背对着的时候 分别为两个方向背对的时候 { //前面有讲到distance不为0时表示目标为玩家,此时进行转向的判定 //表示目标为人 if (distance != 0) { //humanBody targetBody = target.GetComponent<humanBody>(); if (((target.transform.position.x < body.transform.position.x && body.direction == 1) || (target.transform.position.x > body.transform.position.x && body.direction == 0))) { position += AITool.ApproachOrAway(target, body, -0.9f, speed, e); } else { body.StopWalk(); } //if (targetBody.direction == body.direction) //{ // //表示要转向了. // //再调用一次,这次肯定会转向 //} } else { //目标为物体 body.StopWalk(); } } } return(position); }