void Start() { lastHitTime = 1f; animator = GetComponent <Animator>(); enemy = GetComponent <NavMeshAgent2D>(); animator.SetBool("PlayerKicking", false); player = GameObject.FindGameObjectWithTag("Player").transform; formerStatus = new bool[3]; playerCollider = null; if (isSit) { animator.SetBool("IsSit", true); } if (audioE == null) { audioE = GetComponentInChildren <AudioSource>(); } if (lineOfSight == 0) { lineOfSight = 10.0f; } ApplyAnimationEventToKickAnimation(CreateAnimationEvent()); //enemy.destination = player.position; }
void OnDrawGizmos() { // only while game is running, otherwise navmeshagent2d has no 3d agent. if (Application.isPlaying) { // can't cache agent because reloading script sometimes clears cached NavMeshAgent2D agent = GetComponent <NavMeshAgent2D>(); // get path NavMeshPath2D path = agent.path; // color depends on status Color color = Color.white; switch (path.status) { case NavMeshPathStatus.PathComplete: color = Color.white; break; case NavMeshPathStatus.PathInvalid: color = Color.red; break; case NavMeshPathStatus.PathPartial: color = Color.yellow; break; } // draw the path for (int i = 1; i < path.corners.Length; ++i) { Debug.DrawLine(path.corners[i - 1], path.corners[i], color); } // draw velocity Debug.DrawLine(transform.position, transform.position + (Vector3)agent.velocity, Color.blue, 0, false); } }
protected virtual void Awake() { navi = GetComponent <NavMeshAgent2D>(); player = GameObject.FindGameObjectWithTag("Player"); stopMovement = false; patrolPositions.Add(transform.position); actions = new EnemyActions(player, gameObject); baseSpeed = GetComponent <NavMeshAgent2D>().speed; weaknessMultiplier = 2; electricEffect = gameObject.transform.Find("ElectricEffect").gameObject.GetComponent <ParticleSystem>(); fireEffect = gameObject.transform.Find("FireEffect").gameObject.GetComponent <ParticleSystem>(); freezeEffect = gameObject.transform.Find("FrostEffect").gameObject.GetComponent <ParticleSystem>(); electricEffectEm = electricEffect.emission; electricEffectEm.enabled = false; fireEffectEm = fireEffect.emission; fireEffectEm.enabled = false; freezeEffectEm = freezeEffect.emission; freezeEffectEm.enabled = false; }
// NavMeshAgent helper function that returns the nearest valid point for a // given destination. This is really useful for click & wsad movement // because the player may click into all kinds of unwalkable paths: // // ________ // |xxxxxxx| // |x| |x| // P A|B| C |x| // |x|___|x| // |xxxxxxx| // // if a player is at position P and tries to go to: // - A: the path is walkable, everything is fine // - C: C is on a NavMesh, but we can't get there directly. CalcualatePath // will return A as the last walkable point // - B: B is not on a NavMesh, CalulatePath doesn't work here. We need to // find the nearest point on a NavMesh first (might be A or C) and then // calculate the nearest valid one (A) public static Vector2 NearestValidDestination(this NavMeshAgent2D agent, Vector2 destination) { // can we calculate a path there? then return the closest valid point NavMeshPath2D path = new NavMeshPath2D(); if (agent.CalculatePath(destination, path)) { return(path.corners[path.corners.Length - 1]); } // otherwise find nearest navmesh position first. we use a radius of // speed*2 which works fine. afterwards we find the closest valid point. NavMeshHit hit; if (NavMesh.SamplePosition(new Vector3(destination.x, 0, destination.y), out hit, agent.speed * 2, NavMesh.AllAreas)) { Vector2 hitPosition2D = new Vector2(hit.position.x, hit.position.z); if (agent.CalculatePath(hitPosition2D, path)) { return(path.corners[path.corners.Length - 1]); } } // nothing worked, don't go anywhere. return(agent.transform.position); }
void Start() { agent = GetComponent <NavMeshAgent2D>(); collider = GetComponent <BoxCollider2D>(); animator = GetComponent <Animator>(); animator.SetBool("IsDead", false); }
virtual protected void Awake() { mTrans = transform; navMeshAgent2D = GetComponent <NavMeshAgent2D>(); animationManager = GetComponent <AnimationManager>(); bodyRender = GetComponentInChildren <SpriteRenderer>(); }
private void Awake() { curHealth = maxHealth; nav = GetComponent <NavMeshAgent2D>(); hitbox = GetComponent <BoxCollider2D>(); rb = GetComponent <Rigidbody2D>(); curAttackRange = attackRange; }
void Start() { _nav2D = GetComponent <NavMeshAgent2D>(); _audio = GetComponent <AudioSource>(); _anim = GetComponent <Animator>(); _collider = GetComponent <CircleCollider2D>(); _transform = GetComponent <Transform>(); }
void Start() { agent = GetComponent <NavMeshAgent2D>(); currentPosition = transform.position; //redCells = GameObject.FindGameObjectsWithTag("Target").ToList(); ; //gets all remaining red cells when spawned FindTarget(); }
void Start() { RateOfFire = 1.0f / RateOfFire; Player = GameObject.FindGameObjectWithTag("Player").transform; Agent = GetComponent <NavMeshAgent2D>(); Agent.SetDestination(Player.position); LastBulletTimer = 0.0f; }
void Awake() { stateMachine = new StateMachine <Crawler>(this); stateMachine.ChangeState(CrawlerIdle.Instance); nav2D = GetComponent <NavMeshAgent2D>(); anim = GetComponent <Animator>(); _trigger = GetComponent <BoxCollider2D>(); _RB = GetComponent <Rigidbody2D>(); }
void Update() { if (Input.GetMouseButton(0)) { Vector3 w = Camera.main.ScreenToWorldPoint(Input.mousePosition); NavMeshAgent2D g = GetComponent <NavMeshAgent2D>(); GetComponent <NavMeshAgent2D>().destination = w; } }
void Awake() { animator = GetComponent <Animator>(); enemy = GetComponent <NavMeshAgent2D>(); player = GameObject.FindGameObjectWithTag("Player").transform; enemy.speed = speed; if (audioE == null) { audioE = GetComponentInChildren <AudioSource>(); } }
// Start is called before the first frame update void Start() { agent = GetComponent <NavMeshAgent2D>(); player = GameObject.FindWithTag("Player"); playerPos = player.GetComponent <Transform>(); GoToNextPoint(); }
// Start is called before the first frame update private void Start() { Debug.Assert(ParentTilemapGroup != null); _currentCapacity = DefaultRoombaCapacity; navMeshAgent2D = GetComponent <NavMeshAgent2D>(); _doodadsBackgroundTilemap = ParentTilemapGroup.Tilemaps.First(tilemap => tilemap.name == "DoodadsBackground"); _doodadsForegroundTilemap = ParentTilemapGroup.Tilemaps.First(tilemap => tilemap.name == "DoodadsForeground"); Debug.Assert(_doodadsBackgroundTilemap != null); Debug.Assert(_doodadsForegroundTilemap != null); }
void Awake() { animator = GetComponent <Animator>(); lastHitTime = 1f; enemy = GetComponent <NavMeshAgent2D>(); player = GameObject.FindGameObjectWithTag("Player").transform; enemy.speed = speed; if (audioE == null) { audioE = GetComponentInChildren <AudioSource>(); } //ApplyAnimationEventToKickAnimation(CreateAnimationEvent()); }
// Start is called before the first frame update void Start() { timer = new QuickTimer(); pointers = new List <Vector3>(); maxIdleDelay = useOnlyMinIdle ? minIdleDelay : Random.Range(minIdleDelay, maxIdleDelay); m_nav = gameObject.GetComponent <NavMeshAgent2D>(); m_animator = gameObject.GetComponent <Animator>(); //Initialize player reference var players = GameObject.FindGameObjectsWithTag("Player"); if (players.Length > 1) { print("Error, more than one Player!"); } else if (players.Length < 1) { print("Error, no Player!"); } else { player = players[0]; } //Initialize goals if necessary if (goals.Count == 0 || goals[0] == null) { var goalList = GameObject.FindGameObjectsWithTag("EnemyWaypoint"); goals = new List <GameObject>(goalList); } alertSprite = transform.Find("AlertSprite").gameObject; alert_animator = alertSprite.GetComponent <Animator>(); vision = GetComponentInChildren <VisionCone>(); vision.viewDistance = maxVisionDistance; vision.fov = visionConeAngle * 2; Vector3 hearingCircleScale = transform.Find("VisionCircle").localScale; hearingCircleScale.x = 2f * maxHearingDistance; hearingCircleScale.y = 2f * maxHearingDistance; transform.Find("VisionCircle").localScale = hearingCircleScale; this.originalSpeed = m_nav.speed; }
void Start() { rigidbody = this.GetComponent <Rigidbody2D>(); transform = this.GetComponent <Transform>(); navMeshAgent = GetComponent <NavMeshAgent2D>(); singleValue = MoodValueMAX / 3; MoodValueCurrent = MoodValueInit; GameObject gb = GameObject.FindGameObjectWithTag("MoodValue"); MoodValueIcons = gb.GetComponentsInChildren <Image>(); MoodAlter(); //bulletSpawnPoint = this.gameObject.GetComponentsInChildren<Transform>()[1]; enemys = GameObject.FindGameObjectsWithTag("Enemy"); source = transform.position; }
void Start() { bulletSpawnPoint = this.gameObject.GetComponentsInChildren <Transform>()[1]; player = GameObject.FindGameObjectWithTag("Player"); navMeshAgent = this.GetComponent <NavMeshAgent2D>(); prop = (GameObject)Resources.Load(path); camerashake = Camera.main.GetComponent <CameraShake>(); door = GameObject.FindGameObjectWithTag("Door"); changeColor = Camera.main.GetComponent <ChangeColor>(); vspeed = 0; hspeed = speed; xdelta = 2; ydelta = 0; source = transform.position; }
// Initiates all variables. void Start() { targetKamikaze = player.transform; sceneController = GameObject.FindGameObjectWithTag("SceneController").GetComponent("SceneController") as SceneController; isLock = false; isShooting = false; randomDestination = UnityEngine.Random.Range(0, destinations.childCount); nav = GetComponent <NavMeshAgent2D>(); fixedDestinations = new Transform[destinations.childCount]; for (int i = 0; i < destinations.childCount; i++) { fixedDestinations[i] = destinations.GetChild(i); fixedDestinations[i].position = new Vector3((fixedDestinations[i].position.x * 2) + 200, (fixedDestinations[i].position.y * 3) + 75, 0); } Vector3 w = Camera.main.ScreenToWorldPoint(fixedDestinations[randomDestination].position); nav.destination = w; destinationSet = true; }
private void Start() { idleTimer = new QuickTimer(); m_nav = gameObject.GetComponent <NavMeshAgent2D>(); goals = new List <GameObject>(); foreach (GameObject g in GameObject.FindGameObjectsWithTag("Treasure")) { goals.Add(g); print(g.name); } ChangePlayerState(PlayerStates.IDLE); m_animator = GetComponent <Animator>(); coinLocations = new List <Transform>(); GameObject gm = GameObject.FindGameObjectWithTag("Manager"); gameManager = gm != null?gm.GetComponent <GameProgressTracker>() : null; if (gameManager != null) { if (gameManager.canReturn) { GameObject pos = GameObject.Find("ReturnPosition"); m_nav.Warp(pos.transform.position); GameObject g = GameObject.Find("Exit"); goals.Add(g); g.GetComponent <doorController>().enabled = true; } } a_source = gameObject.GetComponent <AudioSource>(); this.originalSpeed = m_nav.speed; }
void Start() { speaker = GetComponent <AudioSource>(); FOV = GetComponentInChildren <SpiritView>().gameObject; nav = GetComponent <NavMeshAgent2D>(); rig = GetComponent <Rigidbody2D>(); emotions = GetComponent <AnimationManager>(); displayInventory = GetComponentInChildren <Text>(); //inventory.text = "hi"; // fill with terminals, for navigation between them terminalList = GameObject.FindGameObjectsWithTag("terminal"); terminals.AddRange(terminalList); //sets initial random target terminal for spirits int i = UnityEngine.Random.Range(0, terminals.Count); previousPosition = i; idleDest = terminals[i].transform.position; spiritState = SpiritState.Idle; ogTerminalWaitTime = terminalWaitTime; goldInventory = UnityEngine.Random.Range(4, 7); }
// NavMeshAgent's ResetPath() function clears the path, but doesn't clear // the velocity immediately. This is a nightmare for finite state machines // because we often reset a path, then switch to casting, which would then // receive a movement event because velocity still isn't 0 until a few // frames later. // // We need a function that truly stops all movement. public static void ResetMovement(this NavMeshAgent2D agent) { agent.ResetPath(); agent.velocity = Vector2.zero; }
void Start() { agent = GetComponent <NavMeshAgent2D>(); //waypoints = GameObject.FindGameObjectsWithTag("Destination"); GoToNextPoint(); //goes to first destination in planned path }
protected override void Awake() { base.Awake(); navigationAgent = GetComponent <NavMeshAgent2D>(); }
void Start() { _nav = GetComponent <NavMeshAgent2D>(); startPosition = transform.position; timeTillNextMove = Random.Range(timerMin, timerMax); }
IEnumerator FadeAndDie() { GameObject[] allObjects = UnityEngine.Object.FindObjectsOfType <GameObject>(); float alpha = 1f; // make player invisible, and stop moving GameObject player = GameObject.FindGameObjectWithTag("Player"); Vector3 pos = player.transform.position; player.GetComponent <SpriteRenderer>().enabled = false; player.GetComponent <CharacterController> ().enabled = false; player.GetComponent <Rigidbody2D>().velocity = Vector2.zero; //player.GetComponent<CircleCollider2D>().enabled = false; // spawn dying prefab GameObject dyingPlayer = Instantiate(dyingPrefab); dyingPlayer.transform.position = pos; dyingPlayer.transform.parent = player.transform; dyingPlayer.GetComponent <EnemyAI>().isDead = true; dyingPlayer.GetComponent <Animator>().SetBool("IsEnemyDead", true); // spawn dead text GameOverText.text = "GAME OVER"; // slowly fade in text // slowly fade out all other objects while (alpha > -1f) { foreach (GameObject go in allObjects) { if (go == null) { continue; } if (go.gameObject.tag == "Player") { continue; } NavMeshAgent2D e = go.gameObject.GetComponent <NavMeshAgent2D>(); if (e) { e.Stop(); } SpriteRenderer sr = go.GetComponent <SpriteRenderer>(); if (sr) { Color c = sr.color; c.a = Mathf.Max(0f, alpha); sr.color = c; } } alpha -= Time.deltaTime * 0.3f; //player.transform.position = pos; yield return(new WaitForEndOfFrame()); } startedDying = false; GameOverText.text = ""; GameMaster.SoftReset(); }
void Start() { nav = GetComponent <NavMeshAgent2D>(); }
// Use this for initialization void Start() { navMesh = GetComponentInParent <NavMeshAgent2D>(); anim = GetComponent <FDAnimation>(); }
// Start is called before the first frame update void Start() { agent = GetComponent <NavMeshAgent2D>(); animator = GetComponent <Animator>(); }