//----------------------------------------------------- // Setting up all AI behaviour components // // Jump across platforms, fire laser at player, jump to new platform //----------------------------------------------------- void Start() { //Set health SetHealth(m_healthMax); m_selectorTop = gameObject.AddComponent <BehaviourSelector>(); m_gettingTarget = gameObject.AddComponent <BehaviourSequence>(); m_selectorAction = gameObject.AddComponent <BehaviourSelector>(); m_sequenceFiring = gameObject.AddComponent <BehaviourSequence>(); m_sequenceLaser = gameObject.AddComponent <BehaviourSequence>(); //Laser m_actionGetDisLaser = gameObject.AddComponent <IsTargetCloseEnough>(); m_actionFireLaser = gameObject.AddComponent <FireLaserbeam>(); m_actionLaserCooldown = gameObject.AddComponent <CoolDown>(); m_jumpToPlatform = gameObject.AddComponent <JumpToPlatform>(); m_landingCooldown = gameObject.AddComponent <CoolDown>(); //Set up get target if (GameObject.FindWithTag("GameController").GetComponent <GameManager>().m_singlePlayer) { m_actionGetTarget = gameObject.AddComponent <GetTargetSinglePlayer>(); } else { switch (m_difficulty) { case Difficulty.Easy: { m_actionGetTarget = gameObject.AddComponent <GetTargetEasy>(); break; } case Difficulty.Medium: { m_actionGetTarget = gameObject.AddComponent <GetTargetMedium>(); break; } case Difficulty.Hard: { m_actionGetTarget = gameObject.AddComponent <GetTargetHard>(); break; } } } m_selectorTop.m_behaviourBranches.Add(m_gettingTarget); m_selectorTop.m_behaviourBranches.Add(m_jumpToPlatform); m_gettingTarget.m_behaviourBranches.Add(m_actionGetTarget as BehaviourBase); m_gettingTarget.m_behaviourBranches.Add(m_selectorAction); m_selectorAction.m_behaviourBranches.Add(m_sequenceFiring); m_sequenceFiring.m_behaviourBranches.Add(m_sequenceLaser); m_sequenceFiring.m_behaviourBranches.Add(m_jumpToPlatform); m_sequenceFiring.m_behaviourBranches.Add(m_landingCooldown); m_sequenceLaser.m_behaviourBranches.Add(m_actionGetDisLaser); m_sequenceLaser.m_behaviourBranches.Add(m_actionFireLaser); m_sequenceLaser.m_behaviourBranches.Add(m_actionLaserCooldown); m_sequenceLaser.m_behaviourBranches.Add(m_jumpToPlatform); //Laser m_actionGetDisLaser.m_targetDistance = m_laserFireDistance; m_actionFireLaser.m_chargeRate = m_laserChargeTime; m_actionFireLaser.m_laserSpawnPos = m_laserPos; m_actionFireLaser.m_laserFriendlyFire = m_laserFriendlyFire; m_actionFireLaser.m_laserFollowing = m_laserFollowing; m_actionLaserCooldown.m_coolDown = m_laserCooldown; m_actionFireLaser.m_laserbeam = m_laserPrefab; //Jumping m_jumpToPlatform.m_jumpHeight = m_jumpHeight; m_jumpToPlatform.m_jumpTime = m_jumpTime; m_landingCooldown.m_coolDown = m_landingTimer; m_initalBehaviour = m_selectorTop; }
//----------------------------------------------------- // Setting up all AI behaviour components // // Fire left claw, fire right and laser at same time //----------------------------------------------------- void Start() { //Set health SetHealth(m_healthMax); m_sequenceTop = gameObject.AddComponent <BehaviourSequence>(); m_firingParallel = gameObject.AddComponent <BehaviourParallel>(); m_sequenceLeftGun = gameObject.AddComponent <BehaviourSequence>(); m_sequenceRightGun = gameObject.AddComponent <BehaviourSequence>(); m_sequenceLaser = gameObject.AddComponent <BehaviourSequence>(); m_actionGetTarget = gameObject.AddComponent <BehaviourBase>(); //LeftClaw m_actionFireLeftGun = gameObject.AddComponent <FireGun>(); //RightClaw m_actionFireRightGun = gameObject.AddComponent <FireGun>(); //Both Claws m_actionGetDisGun = gameObject.AddComponent <IsTargetCloseEnough>(); m_actionGunCooldown = gameObject.AddComponent <CoolDown>(); //Laser m_actionGetDisLaser = gameObject.AddComponent <IsTargetCloseEnough>(); m_actionFireLaser = gameObject.AddComponent <FireLaserbeam>(); m_actionLaserCooldown = gameObject.AddComponent <CoolDown>(); //Set up get target if (GameObject.FindWithTag("GameController").GetComponent <GameManager>().m_singlePlayer) { m_actionGetTarget = gameObject.AddComponent <GetTargetSinglePlayer>(); } else { switch (m_difficulty) { case Difficulty.Easy: { m_actionGetTarget = gameObject.AddComponent <GetTargetEasy>(); break; } case Difficulty.Medium: { m_actionGetTarget = gameObject.AddComponent <GetTargetMedium>(); break; } case Difficulty.Hard: { m_actionGetTarget = gameObject.AddComponent <GetTargetHard>(); break; } } } //Left gun m_actionGetDisGun.m_targetDistance = m_gunFireDistance; m_actionFireLeftGun.m_numberOfBullets = m_gunNumberOfShots; m_actionFireLeftGun.m_timeBetweenShots = m_gunTimeBetweenShots; m_actionFireLeftGun.m_bulletSpeed = m_gunBulletSpeed; m_actionFireLeftGun.m_bulletSpawnPos = m_leftClawPos; m_actionFireLeftGun.m_bullet = m_bulletPrefab; m_actionGunCooldown.m_coolDown = m_gunCooldown; //Right gun m_actionGetDisGun.m_targetDistance = m_gunFireDistance; m_actionFireRightGun.m_numberOfBullets = m_gunNumberOfShots; m_actionFireRightGun.m_timeBetweenShots = m_gunTimeBetweenShots; m_actionFireRightGun.m_bulletSpeed = m_gunBulletSpeed; m_actionFireRightGun.m_bulletSpawnPos = m_rightClawPos; m_actionFireRightGun.m_bullet = m_bulletPrefab; m_actionGunCooldown.m_coolDown = m_gunCooldown; //Laser m_actionGetDisLaser.m_targetDistance = m_laserFireDistance; m_actionFireLaser.m_chargeRate = m_laserChargeTime; m_actionFireLaser.m_laserSpawnPos = m_laserPos; m_actionFireLaser.m_laserFriendlyFire = m_laserFriendlyFire; m_actionFireLaser.m_laserFollowing = m_laserFollowing; m_actionFireLaser.m_laserbeam = m_laserPrefab; m_actionLaserCooldown.m_coolDown = m_laserCooldown; //Set up branches m_sequenceTop.m_behaviourBranches.Add(m_actionGetTarget as BehaviourBase); m_sequenceTop.m_behaviourBranches.Add(m_sequenceLeftGun); m_sequenceTop.m_behaviourBranches.Add(m_firingParallel); m_firingParallel.m_behaviourBranches.Add(m_sequenceLaser); m_firingParallel.m_behaviourBranches.Add(m_sequenceRightGun); m_sequenceLeftGun.m_behaviourBranches.Add(m_actionGetDisGun); m_sequenceLeftGun.m_behaviourBranches.Add(m_actionFireLeftGun); m_sequenceLeftGun.m_behaviourBranches.Add(m_actionGunCooldown); m_sequenceRightGun.m_behaviourBranches.Add(m_actionGetDisGun); m_sequenceRightGun.m_behaviourBranches.Add(m_actionFireRightGun); m_sequenceRightGun.m_behaviourBranches.Add(m_actionGunCooldown); m_sequenceLaser.m_behaviourBranches.Add(m_actionGetDisLaser); m_sequenceLaser.m_behaviourBranches.Add(m_actionFireLaser); m_sequenceLaser.m_behaviourBranches.Add(m_actionLaserCooldown); m_initalBehaviour = m_sequenceTop; }