private void SetListOfObstaclesConstructed() { m_nbTtraps = 0; m_obstaclesConstructedIndList.Clear(); m_obstaclesConstructedByBotIndList.Clear(); for (int i = 0; i < m_listObstacles.Count; i++) { if (IsObstaclesBuilt(new List <int> () { i })) { m_obstaclesConstructedIndList.Add(i); ActiveObstacle activeObstacle = m_listObstacles[i].transform.GetComponentInChildren <ActiveObstacle> (); if (activeObstacle == null) { //Debug.Log("activeObstacle est null"); return; } PlayerEntity.Player playerNumber = activeObstacle.GetPlayerNumber(); if (playerNumber == PlayerEntity.Player.Bot) { if (null != m_listObstacles[i].transform.Find("Trap_A(Clone)")) { m_nbTtraps++; } m_obstaclesConstructedByBotIndList.Add(i); } } } }
private bool IsEnoughBombToDestroy(List <int> listIndObstacles) { int nbPlayersObstacles = 0; for (int i = 0; i < listIndObstacles.Count; i++) { if (IsObstaclesBuilt(new List <int> () { listIndObstacles[i] })) { ActiveObstacle activeObstacle = m_listObstacles[listIndObstacles[i]].transform.GetComponentInChildren <ActiveObstacle> (); if (null == activeObstacle) { continue; } PlayerEntity.Player playerNumber = activeObstacle.GetPlayerNumber(); if (playerNumber != PlayerEntity.Player.Bot) { nbPlayersObstacles++; } } } return(nbPlayersObstacles <= GameManager.Instance.GetPlayer(PlayerEntity.Player.Bot).GetComponent <Bomb> ().GetBombStack()); }
// 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) { m_activeObstacle = m_obstacleConstructorList[m_index].transform.GetComponentInChildren <ActiveObstacle>(); m_playerNumber = m_activeObstacle.GetPlayerNumber(); if (m_playerNumber != PlayerEntity.Player.Bot && m_playerEntity.GetComponent <Bomb>().GetBombStack() > 0 && m_obstacleConstructorList[m_index].GetCurrentState() == ObstacleConstructor.EState.Built) { m_playerEntity.GetComponent <Bomb>().UseBombStack(); m_playerEntity.CmdBomb(m_activeObstacle.gameObject); } if (m_playerNumber == PlayerEntity.Player.Bot && m_obstacleConstructorList[m_index].GetCurrentState() == ObstacleConstructor.EState.Built) { m_activeObstacle.CmdDestroyObstacle(); } animator.SetTrigger(Constant.BotTransition.s_return); }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { m_pathCorners = m_playerUnit.GetAgent().path.corners; RaycastHit enter; float minDistance = Mathf.Infinity; for (int i = 0; i < m_pathCorners.Length - 1; i++) { Vector2 line = new Vector2(m_pathCorners[i + 1].x - m_pathCorners[i].x, m_pathCorners[i + 1].z - m_pathCorners[i].z); Vector2 lineDir = line.normalized; Ray lineRay = new Ray(m_pathCorners[i], lineDir); Debug.DrawLine(m_pathCorners[i], m_pathCorners[i + 1], Color.green, 1000, false); for (int j = 0; j < m_listObstacles.Count; j++) { ObstacleConstructor obstacle = m_listObstacles[j]; Vector3 obstaclePos = obstacle.transform.position; Vector3 obstacleRot = obstacle.transform.eulerAngles; Vector3 obstacleNormal; if (obstacleRot.y == 90) { obstacleNormal = Vector3.right; } else { obstacleNormal = Vector3.forward; } GameObject plan = new GameObject(); plan.AddComponent <BoxCollider>(); plan.transform.position = obstaclePos; plan.GetComponent <BoxCollider>().transform.localScale += new Vector3(5f, 5f, 5f); if (plan.GetComponent <BoxCollider>().Raycast(lineRay, out enter, Vector3.Distance(m_pathCorners[i], m_pathCorners[i + 1]))) { Vector3 hitPoint = enter.point; if (Vector3.Distance(hitPoint, obstaclePos) < 5f) { float distance = Vector3.Distance(hitPoint, m_pathCorners[i]); if ((distance < minDistance) && (distance > Vector3.Distance(m_playerUnit.transform.position, m_pathCorners[i]))) { minDistance = distance; m_indexObstacle = j; } } } Destroy(plan); } } // Prepare pour Build Obstacles ActiveObstacle activeObstacle = m_listObstacles[m_indexObstacle].transform.GetComponentInChildren <ActiveObstacle>(); if (null != activeObstacle) { PlayerEntity.Player playerNumber = activeObstacle.GetPlayerNumber(); if (playerNumber == PlayerEntity.Player.Player1) { m_aiDestroyObstacle.SetIndex(m_indexObstacle); animator.SetTrigger(Constant.BotTransition.s_destroyObstacle); } } m_aiBuildObstacles.SetTypeBuild(m_buildType); m_aiBuildObstacles.SetIndex(m_indexObstacle); animator.SetTrigger(Constant.BotTransition.s_buildObstacle); }