private void ConstructFSM()
    {
        //Get the list of points
        //   pointList = GameObject.FindGameObjectsWithTag("WandarPoint");
        var pointList = gameObject.transform.Cast <Transform>().Where(c => c.gameObject.tag == "WandarPoint").Select(c => c.gameObject).ToArray();

        Transform[] waypoints = new Transform[pointList.Length];
        int         i         = 0;


        foreach (GameObject obj in pointList)
        {
            obj.GetComponent <Transform>().position = transform.position + new Vector3(Random.onUnitSphere.x * 5,
                                                                                       Random.onUnitSphere.y * 5, Random.onUnitSphere.z * 5);
            waypoints[i] = obj.transform;
            //	waypoints[i].position = new Vector3(Random.insideUnitSphere.x * 5,
            //	                                    Random.insideUnitSphere.z * 5, Random.insideUnitSphere.z * 5);

            i++;
        }

        PatrolState patrol = new PatrolState(waypoints);

        patrol.AddTransition(FSMTransition.PlayerSeen, StateID.Chasing);
        patrol.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        patrol.SetStateDistances(chaseStartDist, attackStartDist);
        patrol.SetSpeed(speed / 2, rotationSpeed / 2);
        patrol.SetBounds(patrolBounds.x, patrolBounds.y, patrolBounds.z);

        ChaseState chase = new ChaseState(waypoints);

        chase.AddTransition(FSMTransition.PlayerLost, StateID.Patrolling);
        chase.AddTransition(FSMTransition.PlayerReached, StateID.Attacking);
        chase.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        chase.SetStateDistances(chaseStartDist, attackStartDist);
        chase.SetSpeed(speed, rotationSpeed);

        AttackState attack = new AttackState(waypoints);

        attack.AddTransition(FSMTransition.PlayerLost, StateID.Patrolling);
        attack.AddTransition(FSMTransition.PlayerSeen, StateID.Chasing);
        attack.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        attack.SetStateDistances(chaseStartDist, attackStartDist);
        attack.SetSpeed(speed, rotationSpeed);
        attack.kamikaze = this.kamikaze;

        DeadState dead = new DeadState();

        dead.AddTransition(FSMTransition.NoHealth, StateID.Dead);

        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);

        //Start patrolling at given points
        patrol.FindNextPoint();
    }
    private void ConstructFSM()
    {
        //Get the list of points
        //   pointList = GameObject.FindGameObjectsWithTag("WandarPoint");
        var pointList = gameObject.transform.Cast<Transform>().Where(c => c.gameObject.tag == "WandarPoint").Select(c => c.gameObject).ToArray();

        Transform[] waypoints = new Transform[pointList.Length];
        int i = 0;

        foreach (GameObject obj in pointList)
        {
            obj.GetComponent<Transform>().position = transform.position + new Vector3(Random.onUnitSphere.x * 5,
                                                                 Random.onUnitSphere.y * 5, Random.onUnitSphere.z * 5);
            waypoints[i] = obj.transform;
            //	waypoints[i].position = new Vector3(Random.insideUnitSphere.x * 5,
            //	                                    Random.insideUnitSphere.z * 5, Random.insideUnitSphere.z * 5);

            i++;
        }

        PatrolState patrol = new PatrolState(waypoints);
        patrol.AddTransition(FSMTransition.PlayerSeen, StateID.Chasing);
        patrol.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        patrol.SetStateDistances(chaseStartDist, attackStartDist);
        patrol.SetSpeed(speed / 2, rotationSpeed / 2);
        patrol.SetBounds(patrolBounds.x, patrolBounds.y, patrolBounds.z);

        ChaseState chase = new ChaseState(waypoints);
        chase.AddTransition(FSMTransition.PlayerLost, StateID.Patrolling);
        chase.AddTransition(FSMTransition.PlayerReached, StateID.Attacking);
        chase.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        chase.SetStateDistances(chaseStartDist, attackStartDist);
        chase.SetSpeed(speed, rotationSpeed);

        AttackState attack = new AttackState(waypoints);
        attack.AddTransition(FSMTransition.PlayerLost, StateID.Patrolling);
        attack.AddTransition(FSMTransition.PlayerSeen, StateID.Chasing);
        attack.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        attack.SetStateDistances(chaseStartDist, attackStartDist);
        attack.SetSpeed(speed, rotationSpeed);
        attack.kamikaze = this.kamikaze;

        DeadState dead = new DeadState();
        dead.AddTransition(FSMTransition.NoHealth, StateID.Dead);

        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);

        //Start patrolling at given points
        patrol.FindNextPoint();
    }