// Use for initialising the companion
    void Start()
    {
        // Turns off companion hack script, change the emission texture of the companion and make it moveable
        CompanionHackScript companionHack = gameObject.GetComponent <CompanionHackScript>();

        companionHack.enabled = false;
        GetComponent <Renderer>().material.SetTexture("_EmissionMap", companionTexture);
        GetComponent <Rigidbody>().isKinematic = false;


        // Initialise behaviour list
        m_behaviours = new List <IBehaviour>();

        // Find the player game object
        player       = FindObjectOfType <FPSController>().gameObject;
        playerScript = player.GetComponent <FPSController>();

        //-----------------------------------------------------------------
        // The Flee Sequence

        // Set up the flee force and flee force parameter
        m_fleeForce = new HorizontalFleeForce();
        m_fleeForce.SetTarget(player /*.transform.position + new Vector3 (2, 2, 2)*/);

        // Set up the flee behaviour
        fleeBehaviour = new SteeringBehaviour();
        fleeBehaviour.Constructor();
        fleeBehaviour.AddNewForce(m_fleeForce);

        // Set up condition for flee sequence
        WithinRange fleeCondition = new WithinRange();

        fleeCondition.SetParameters(player, 2.0f);

        // Set up flee sequence
        Sequence fleeSequence = new Sequence();

        fleeSequence.addBehaviour(fleeCondition);
        fleeSequence.addBehaviour(fleeBehaviour);



        //-----------------------------------------------------------------
        // The Chase Sequence

        // Set up the seek force and seek force parameter
        m_seekForce = new SeekForce();
        m_seekForce.SetTarget(player /*.transform.position + new Vector3 (2, 2, 2)*/);

        // Set up the seek behaviour
        seekBehaviour = new SteeringBehaviour();
        seekBehaviour.Constructor();
        seekBehaviour.AddNewForce(m_seekForce);

        // Set up condition for chase sequence
        WithinRange chaseCondition = new WithinRange();

        chaseCondition.SetParameters(player, 3.5f);

        // Set up the reverse condition
        NotCondition notChase = new NotCondition();

        notChase.SetCondition(chaseCondition);

        // Set up chase sequence
        Sequence chaseSequence = new Sequence();

        chaseSequence.addBehaviour(notChase);
        chaseSequence.addBehaviour(seekBehaviour);


        //-----------------------------------------------------------------
        // The In Range Sequence

        // Companion in range behaviour

        CompanionInRange inRangeBehaviour = new CompanionInRange();

        inRangeBehaviour.SetPlayer(player);


        //----------------------------------------------------------------
        // The Main Selector

        // Set up main selector
        Selector mainSelector = new Selector();

        mainSelector.addBehaviour(fleeSequence);
        mainSelector.addBehaviour(chaseSequence);
        mainSelector.addBehaviour(inRangeBehaviour);


        // Add all sequences to behaviour list
        m_behaviours.Add(mainSelector);

        // Setting the forward direction
        transform.forward = new Vector3(0, 0, 1);
    }
    // Use this for initialization
    void Start()
    {
        // Initialise behaviour list
        m_behaviours = new List <IBehaviour>();

        // Find the player game object
        player       = FindObjectOfType <FPSController>().gameObject;
        playerScript = player.GetComponent <FPSController>();

        currentHealth = maxHealth;

        //-----------------------------------------------------------------
        // The Flee Sequence

        // Set up the flee force and flee force parameter
        m_fleeForce = new HorizontalFleeForce();
        m_fleeForce.SetTarget(player /*.transform.position + new Vector3 (2, 2, 2)*/);

        // Set up the flee behaviour
        fleeBehaviour = new SteeringBehaviour();
        fleeBehaviour.Constructor();
        fleeBehaviour.AddNewForce(m_fleeForce);

        // Set up condition for flee sequence
        WithinRange fleeCondition = new WithinRange();

        fleeCondition.SetParameters(player, 1.5f);

        // Set up flee sequence
        Sequence fleeSequence = new Sequence();

        fleeSequence.addBehaviour(fleeCondition);
        fleeSequence.addBehaviour(fleeBehaviour);

        //-----------------------------------------------------------------
        // The Attack Sequence

        // Set up the attack behaviour
        ShootBehaviour attackBehaviour = new ShootBehaviour();

        attackBehaviour.SetTarget(player);
        attackBehaviour.SetWeaponType(ShootBehaviour.WeaponType.HitScanType);
        List <GameObject> guns = new List <GameObject>();

        // Give a list of bullet spawners to the shoot behaviour
        foreach (Transform child in transform)
        {
            GunParticleSystem gun;
            gun = child.gameObject.GetComponent <GunParticleSystem>();
            if (gun != null)
            {
                guns.Add(gun.gameObject);
            }
        }
        attackBehaviour.SetGuns(guns);

        // Set up condition for the attack sequence
        WithinRange attackCondition = new WithinRange();

        attackCondition.SetParameters(player, attackRange);

        // Set up play sound behaviour
        PlaySound playAttackSound = new PlaySound();

        if (stateAudioSource != null && attackStateClip != null)
        {
            playAttackSound.SetAudioSource(stateAudioSource);
            playAttackSound.SetAudioClip(attackStateClip);
            playAttackSound.SetTimer(15.0f);
        }

        // Set up attack sequence
        Sequence attackSequence = new Sequence();

        attackSequence.addBehaviour(attackCondition);
        if (stateAudioSource != null && attackStateClip != null)
        {
            attackSequence.addBehaviour(playAttackSound);
        }
        attackSequence.addBehaviour(attackBehaviour);



        //-----------------------------------------------------------------
        // The Chase Sequence

        // Set up the seek force and seek force parameter
        m_seekForce = new SeekForce();
        m_seekForce.SetTarget(player);

        // Set up the seek behaviour
        seekBehaviour = new SteeringBehaviour();
        seekBehaviour.Constructor();
        seekBehaviour.AddNewForce(m_seekForce);

        // Set up condition for chase sequence
        WithinRange chaseCondition = new WithinRange();

        chaseCondition.SetParameters(player, chaseRange);

        // Set up play sound behaviour
        PlaySound playChaseSound = new PlaySound();

        if (stateAudioSource != null && chaseStateClip != null)
        {
            playChaseSound.SetAudioSource(stateAudioSource);
            playChaseSound.SetAudioClip(chaseStateClip);
            playChaseSound.SetTimer(15.0f);
        }

        // Set up chase sequence
        Sequence chaseSequence = new Sequence();

        chaseSequence.addBehaviour(chaseCondition);
        if (stateAudioSource != null && chaseStateClip != null)
        {
            chaseSequence.addBehaviour(playChaseSound);
        }
        chaseSequence.addBehaviour(seekBehaviour);



        //----------------------------------------------------------------
        // The Patrol Sequence

        // Set up patrol behaviour
        PatrolBehaviour patrol = new PatrolBehaviour();

        patrol.SetPatrolPoints(m_patrolPointA, m_patrolPointB);
        patrol.StartUp();

        // Set up play sound behaviour
        PlaySound playPatrolSound = new PlaySound();

        if (stateAudioSource != null && chaseStateClip != null)
        {
            playPatrolSound.SetAudioSource(stateAudioSource);
            playPatrolSound.SetAudioClip(patrolStateClip);
            playPatrolSound.SetTimer(15.0f);
        }

        // Set up patrol sequence
        Sequence patrolSequence = new Sequence();

        if (stateAudioSource != null && chaseStateClip != null)
        {
            chaseSequence.addBehaviour(playPatrolSound);
        }
        patrolSequence.addBehaviour(patrol);

        //----------------------------------------------------------------
        // The Main Selector

        // Set up main selector
        Selector mainSelector = new Selector();

        mainSelector.addBehaviour(attackSequence);
        mainSelector.addBehaviour(chaseSequence);
        mainSelector.addBehaviour(patrolSequence);



        // Add all sequences to behaviour list
        m_behaviours.Add(mainSelector);

        // Setting the forward direction
        transform.forward = new Vector3(0, 0, 1);
    }