public Tags.TagNames MoveToTag = Tags.TagNames.Enemy; // the tag the spawned object should move towards // Update is called once per frame void Update() { bool isSpawn = false; // initialize the var we'll check for whether to spawn and object #if UNITY_ANDROID || UNITY_IOS if (UseTouchOnMobile) { int fingerCount = 0; foreach (Touch touch in Input.touches) { if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled) { fingerCount++; } } if (fingerCount > 0) { isSpawn = true; } } #else // spawn object based on key press on standalone platforms if (Input.GetKeyDown(SpawnKey)) { isSpawn = true; } #endif if (isSpawn) { // spawn a prefab at the spawn point if (ObjectToSpawn != null && SpawnPoint != null) { GameObject goInstance = Instantiate(ObjectToSpawn, SpawnPoint.position, Quaternion.identity) as GameObject; // if the game object should move towards the objet with "enemy" tag if (MoveObjectToTag) { GameObject goMoveTowards = GameObject.FindGameObjectWithTag(MoveToTag.ToString()); if (goMoveTowards != null) { // set the enemy as the move toward target MoveTowardsTarget mtt = goInstance.GetComponent <MoveTowardsTarget>(); if (mtt == null) { mtt = goInstance.AddComponent <MoveTowardsTarget> (); } // assign the target object to the instantiated object property -- so it starts moving towards it mtt.Target = goMoveTowards.transform; } } } } }
// Use this for initialization void Start() { _hasTarget = false; _aquireNewTarget = false; _target = null; _unitHalo = GetComponent("Halo") as Behaviour; _movementScript = this.GetComponent<MoveTowardsTarget>(); _unitsInRange = new List<GameObject>(); _anim = GetComponent<Animator>(); //_walkStateId = Animator.StringToHash("Base Layer.Walk"); _idleStateId = Animator.StringToHash("Base Layer.Idle"); _rotateStateId = Animator.StringToHash("Base Layer.Rotate"); }
//----------------------------------------------------- // Setting up all AI behaviour components // // Just move towards player //----------------------------------------------------- void Start() { //Set up varibles m_sequenceTop = gameObject.AddComponent <BehaviourSequence>(); m_sequenceMove = gameObject.AddComponent <BehaviourSequence>(); m_actionGetDisMovement = gameObject.AddComponent <IsTargetCloseEnough>(); m_actionMovetowards = gameObject.AddComponent <MoveTowardsTarget>(); m_actionGetTarget = gameObject.AddComponent <GetTargetSinglePlayer>(); //Movement m_actionGetDisMovement.m_targetDistance = m_moveTowardsRange; //Set up branches m_sequenceTop.m_behaviourBranches.Add(m_actionGetTarget as BehaviourBase); m_sequenceTop.m_behaviourBranches.Add(m_sequenceMove); m_sequenceMove.m_behaviourBranches.Add(m_actionGetDisMovement); m_sequenceMove.m_behaviourBranches.Add(m_actionMovetowards); m_initalBehaviour = m_sequenceTop; }
public static bool Prefix(MoveTowardsTarget __instance) { float aggressionMultiplier; int aggressionRadius; if (CraftData.GetTechType(__instance.gameObject) == TechType.Crash) { return(true); // Explody ambush fish just runs normal method } if (Player.main.precursorOutOfWater || !Player.main.IsUnderwater() || PrecursorMoonPoolTrigger.inMoonpool || (Ocean.main.GetDepthOf(Player.main.gameObject) < 5)) { return(true); } Vehicle veh = Player.main.currentMountedVehicle; if (veh != null) { if (veh.precursorOutOfWater) { return(true); } } //BR// Adjust aggression levels if (Config.DEATHRUN.Equals(DeathRun.config.creatureAggression) || Config.EXORBITANT.Equals(DeathRun.config.creatureAggression)) { if (DayNightCycle.main.timePassedAsFloat > DeathRun.FULL_AGGRESSION) { aggressionMultiplier = 4; aggressionRadius = 6; } else if (DayNightCycle.main.timePassedAsFloat > DeathRun.MORE_AGGRESSION) { aggressionMultiplier = 2; aggressionRadius = 3; } else { return(true); } } else if (Config.HARD.Equals(DeathRun.config.creatureAggression) && (DayNightCycle.main.timePassedAsFloat > DeathRun.MORE_AGGRESSION)) { aggressionMultiplier = 2; aggressionRadius = 3; } else { return(true); // Just run normal method } ProfilingUtils.BeginSample("UpdateCurrentTarget"); if (EcoRegionManager.main != null && (Mathf.Approximately(__instance.requiredAggression, 0f) || __instance.creature.Aggression.Value * aggressionMultiplier >= __instance.requiredAggression)) { IEcoTarget ecoTarget = EcoRegionManager.main.FindNearestTarget(__instance.targetType, __instance.transform.position, __instance.isTargetValidFilter, aggressionRadius); if (ecoTarget != null) { __instance.currentTarget = ecoTarget; } else { __instance.currentTarget = null; } } ProfilingUtils.EndSample(null); return(false); }
//----------------------------------------------------- // Setting up all AI behaviour components // // Move towards player, fire gun, repeat //----------------------------------------------------- void Start() { //Set health SetHealth(m_healthMax); //Set up varibles m_sequenceTop = gameObject.AddComponent <BehaviourSequence>(); m_selectorActions = gameObject.AddComponent <BehaviourSelector>(); //m_sequenceLaser = gameObject.AddComponent<BehaviourSequence>(); m_sequenceGun = gameObject.AddComponent <BehaviourSequence>(); m_sequenceMove = gameObject.AddComponent <BehaviourSequence>(); //m_actionGetDisLaser = gameObject.AddComponent<IsTargetCloseEnough>(); //m_actionFireLaser = gameObject.AddComponent<FireLaserbeam>(); //m_actionLaserCooldown = gameObject.AddComponent<CoolDown>(); m_selectorFiringGun = gameObject.AddComponent <BehaviourSelector>(); m_actionGetDisGun = gameObject.AddComponent <IsTargetCloseEnough>(); m_actionInfrontOfLedge = gameObject.AddComponent <InfrontOfLedge>(); m_actionStopMovement = gameObject.AddComponent <StopMovement>(); m_actionFireGun = gameObject.AddComponent <FireGun>(); m_actionGunCooldown = gameObject.AddComponent <CoolDown>(); m_actionGetDisMovement = gameObject.AddComponent <IsTargetCloseEnough>(); m_actionMovetowards = gameObject.AddComponent <MoveTowardsTarget>(); //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; } } } //Gun m_actionGetDisGun.m_targetDistance = m_gunFireDistance; m_actionFireGun.m_numberOfBullets = m_gunNumberOfShots; m_actionFireGun.m_timeBetweenShots = m_gunTimeBetweenShots; m_actionFireGun.m_bulletSpeed = m_gunBulletSpeed; m_actionFireGun.m_bulletSpawnPos = m_bulletSpawnPos; m_actionGunCooldown.m_coolDown = m_gunCooldown; m_actionFireGun.m_bullet = m_bulletPrefab; //Laser //m_actionGetDisLaser.m_targetDistance = m_laserFireDistance; //m_actionFireLaser.m_chargeRate = m_laserChargeTime; //m_actionLaserCooldown.m_coolDown = m_laserCooldown; //m_actionFireLaser.m_laserbeam = m_laserPrefab; //Movement m_actionGetDisMovement.m_targetDistance = m_moveTowardsRange; //Set up branches m_sequenceTop.m_behaviourBranches.Add(m_actionGetTarget as BehaviourBase); m_sequenceTop.m_behaviourBranches.Add(m_selectorActions); //m_selectorActions.m_behaviourBranches.Add(m_sequenceLaser); m_selectorActions.m_behaviourBranches.Add(m_sequenceGun); m_selectorActions.m_behaviourBranches.Add(m_sequenceMove); //m_sequenceLaser.m_behaviourBranches.Add(m_actionGetDisLaser); //m_sequenceLaser.m_behaviourBranches.Add(m_actionFireLaser); //m_sequenceLaser.m_behaviourBranches.Add(m_actionLaserCooldown); m_selectorFiringGun.m_behaviourBranches.Add(m_actionGetDisGun); m_selectorFiringGun.m_behaviourBranches.Add(m_actionInfrontOfLedge); m_sequenceGun.m_behaviourBranches.Add(m_selectorFiringGun); m_sequenceGun.m_behaviourBranches.Add(m_actionStopMovement); m_sequenceGun.m_behaviourBranches.Add(m_actionFireGun); m_sequenceGun.m_behaviourBranches.Add(m_actionGunCooldown); m_sequenceMove.m_behaviourBranches.Add(m_actionGetDisMovement); m_sequenceMove.m_behaviourBranches.Add(m_actionMovetowards); m_initalBehaviour = m_sequenceTop; }