// Start is called before the first frame update void Start() { animator = gameObject.GetComponentInChildren <Animator>(); rigidBody = transform.GetComponent <Rigidbody2D>(); enemyShoot = gameObject.GetComponent <EnemyShoot>(); enemy = gameObject.GetComponent <Enemy>(); }
/// <summary> /// Initialize references and variables. /// </summary> private void Start() { if (player == null) { player = GameObject.FindGameObjectWithTag("Player"); } controller = GetComponent <CharacterController>(); shootScript = GetComponent <EnemyShoot>(); jumpable = ((1 << LayerMask.NameToLayer("Obstacle")) | (1 << LayerMask.NameToLayer("Explosive") | (1 << LayerMask.NameToLayer("Decoration")))); avoidance = (1 << LayerMask.NameToLayer("Wall") | jumpable); safeRadiusAvg = (safeRadiusMax + safeRadiusMin) / 2; destinationRefreshDistance = safeRadiusAvg - safeRadiusMin; footSize = controller.bounds.extents.y; if (player == null) { Debug.LogError($"{gameObject.name}: No player found!!"); return; } prevPlayerFlatPos = new Vector3(player.transform.position.x, 0, player.transform.position.z); }
public void Start() { EnemyShoot shoot = this.GetComponent <EnemyShoot>(); NonMonoSpellGrid grid = new NonMonoSpellGrid(6, 6); Ink ink = ComponentLoader.GetInstance().LoadComponent(new ComponentLoader.UnLoadedSpellComponent("FireWeedSap", SpellComponent.SubSpellComponentType.Ink)) as Ink; grid.SetInk(ink); grid.SetPixel(2, 2, true); grid.SetPixel(2, 3, true); grid.SetPixel(3, 2, true); grid.SetPixel(3, 3, true); grid.SetPixel(4, 4, true); grid.SetPixel(3, 4, true); grid.SetPixel(4, 3, true); grid.SetPixel(2, 4, true); grid.SetPixel(4, 2, true); grid.SetPixel(3, 1, true); grid.SetPixel(3, 5, true); grid.SetPixel(1, 3, true); grid.SetPixel(5, 3, true); ProjectileSpellBookBuilder spellBuilder = new ProjectileSpellBookBuilder(ProjectileSpellBookBuilder.spellSource.enemy); spellBuilder.caster = gameObject; spellBuilder.grid = grid; spellBuilder.page = ComponentLoader.GetInstance().LoadComponent(new ComponentLoader.UnLoadedSpellComponent("Paper", SpellComponent.SubSpellComponentType.Paper)) as SpellPage; spellBuilder.lang = ComponentLoader.GetInstance().LoadComponent(new ComponentLoader.UnLoadedSpellComponent("English", SpellComponent.SubSpellComponentType.language)) as Language; spellBuilder.SetRune(ComponentLoader.GetInstance().LoadComponent(new ComponentLoader.UnLoadedSpellComponent("Raging Badger", SpellComponent.SubSpellComponentType.Rune)) as SpellRune); shoot.current_spell = spellBuilder.MakeSpellBook(); shoot.coolDown = spellBuilder.page.GetCoolDown(); }
//-------------------------------- // 3 - Shooting from another script //-------------------------------- /// <summary> /// Create a new projectile if possible /// </summary> public void Attack(bool isEnemy) { if (CanAttack) { shootCooldown = shootingRate; // Create a new shot var shotTransform = Instantiate(shotPrefab) as Transform; // Assign position shotTransform.position = transform.position; // The is enemy property EnemyShoot shot = shotTransform.gameObject.GetComponent <EnemyShoot>(); if (shot != null) { shot.isEnemyShot = isEnemy; } // Make the weapon shot always towards it MoveScript move = shotTransform.gameObject.GetComponent <MoveScript>(); if (move != null) { move.direction = this.transform.right; // towards in 2D space is the right of the sprite } } }
void Start() { m_agent = GetComponent <NavMeshAgent>(); m_player = GameObject.FindGameObjectWithTag("Player").transform; m_enemyShoot = gameObject.GetComponent <EnemyShoot>(); m_health = gameObject.GetComponent <EnemyHealth>(); }
public void Reset() { // destroy existing summoned enemies EnemyScout redKnight = GetComponentInChildren <EnemyScout> (); if (redKnight != null) { redKnight.Die(); } EnemyShoot greenKnight = GetComponentInChildren <EnemyShoot> (); if (greenKnight != null) { greenKnight.Die(); } EnemyChaseShoot blackKnight = GetComponentInChildren <EnemyChaseShoot> (); if (blackKnight != null) { blackKnight.Die(); } // reset local vars _existRedKnight = false; _existGreenKnight = false; _existBlackKnight = false; _nextTimeToSummonRedKnight = 0; _nextTimeToSummonGreenKnight = 0; _nextTimeToSummonBlackKnight = 0; }
void Awake() { enemyShoot = GetComponent <EnemyShoot>(); agent = GetComponent <UnityEngine.AI.NavMeshAgent>(); target = GameObject.FindGameObjectWithTag("Player"); enemyRoot = GetComponent <EnemyRoot>(); }
private bool startAnim = true;// just to show animespawn anim; protected override void Start() { base.Start(); playerTransform = GameManager.instance.player.transform; startingPosition = transform.position; delayForChangingPosition = Random.Range(delayChangePosition.x, delayChangePosition.y); if (rangeType == RangedType.horizontal) { minPos = transform.GetChild(0).transform.localPosition.x; maxPos = transform.GetChild(1).transform.localPosition.x; } else if (rangeType == RangedType.Vertical) { minPos = transform.GetChild(0).transform.localPosition.y; maxPos = transform.GetChild(1).transform.localPosition.y; } else { pos1 = transform.GetChild(0).transform.position; pos2 = transform.GetChild(1).transform.position; targetPosition = pos2; } spawnPoint = transform.GetChild(2).transform; enemyShoot = GetComponent <EnemyShoot>(); enemyHealthBar = transform.GetChild(3).GetChild(0).transform; sr.color = Color.black; }
// Update is called once per frame void Update() { while (Time.timeSinceLevelLoad > currEnemy.spawnTime + loopOffset) { print("spawning enemy " + currEnemyIdx + " at time " + currEnemy.spawnTime); GameObject enemyType; switch (currEnemy.enemyType) { case 1: enemyType = EnemyType1; break; case 2: enemyType = EnemyType2; break; case 3: default: enemyType = EnemyType3; break; } GameObject clone = (GameObject)Instantiate(enemyType, currEnemy.spawnPos, Quaternion.identity); clone.transform.parent = this.transform; EnemyType1 script = (EnemyType1)clone.GetComponent("EnemyType1"); script.SetParams(transform.position + currEnemy.spawnPos, transform.position + currEnemy.endPos, currEnemy.speed); EnemyShoot script2 = (EnemyShoot)clone.GetComponent("EnemyShoot"); script2.target = PlayerTarget; currEnemyIdx = (currEnemyIdx + 1) % enemySpawns.Count; currEnemy = (EnemySpawn)enemySpawns[currEnemyIdx]; if (currEnemyIdx == 0) { loopOffset = Time.timeSinceLevelLoad + 5; print("restarting spawn loop"); } } }
// Use this for initialization void Start() { moneyPrefab = GameObject.FindGameObjectWithTag("Money"); player = GameObject.FindGameObjectWithTag("Player"); playersStats = GetComponentInParent <CharacterStats>(); playerHealth = playersStats.maxHealth; playerTP = playersStats.maxTP; Debug.Log("Player Health:" + playerHealth); healthSlider.value = playerHealth; Debug.Log("Player TP:" + playerTP); hasGun = GameObject.FindGameObjectWithTag("enemy"); if (hasGun != null) { shooter = hasGun.GetComponent <EnemyShoot>(); } }
void launchProyectile() { if (currentLife > 0) { // Disparamos las líneas. Vector2 direction = transform.position + new Vector3(marginBulletX, marginBulletY, gameObject.transform.position.z); GameObject goBullet = GameObject.Instantiate <GameObject>(shootPrefab); EnemyShoot classBullet = (EnemyShoot)goBullet.GetComponent("EnemyShoot"); classBullet.enemy = this; // Posición. Transform bullet = goBullet.transform; if (isLookingToRight) { bullet.position = new Vector3(direction.x, direction.y, gameObject.transform.position.z); bullet.GetComponent <Rigidbody2D>().AddForce(new Vector2(bulletVelocityX, 0), ForceMode2D.Impulse); } else { bullet.position = new Vector3(transform.position.x - marginBulletX, direction.y, gameObject.transform.position.z); bullet.GetComponent <Rigidbody2D>().AddForce(new Vector2(-bulletVelocityX, 0), ForceMode2D.Impulse); bullet.localScale = new Vector3(-bullet.localScale.x, bullet.localScale.y, bullet.localScale.x); } // Insertamos sonido de disparo. if (audioShoot != null) { AudioSource currentAS = (AudioSource)gameObject.GetComponent <AudioSource>(); if (currentAS.clip != audioShoot) { currentAS.clip = audioShoot; } currentAS.Play(); } } }
private void Awake() { //I don't need these, but the animation acts weird without disabling these. animator = GetComponent <Animator>(); movement = GetComponent <EnemyAggro>(); attack = GetComponent <EnemyShoot>(); }
public Vector3 ChangeShootPositions(EnemyShoot enemyShoot) { int index = enemyShoot.currentIndex; Vector3 nextPos = GetShootPosition(enemyShoot); ReleaseShootPositions(index); return(nextPos); }
protected override void Awake() { base.Awake(); shootingScript = GetComponentInChildren <EnemyShoot>(); Behave += Idle; Behave += Shoot; Behave += Surrender; }
void Awake() { motor = GetComponent <SimpleMotor3D>(); _shootScript = GetComponent <EnemyShoot>(); //targetLocation = ((GameObject)Instantiate(AttackLocationPrefab, transform.position, Quaternion.identity)).GetComponent<AttackLocation>(); //targetLocation.available = false; }
// Use this for initialization void Start() { transformToFollow = GameObject.FindWithTag("Player"); stopThis = GetComponent<MoveForward>(); shootScript = GetComponent<EnemyShoot>(); if(stopThis!=null) originalSpeed = stopThis.moveSpeed; }
private void Awake() { enemyPathfinding = GetComponent <EnemyPathfinding>(); enemyShoot = GetComponent <EnemyShoot>(); enemyWeapon = transform.GetComponentInChildren <EnemyWeapon>(); moveState = MoveState.Roaming; attackState = AttackState.Idle; }
void Start() { bulletSpeed = 20f; firerate = 5f; nextFireTime = 0; player = GameObject.FindGameObjectWithTag("Player"); enemyShoot = this; }
void Awake() { motor = GetComponent<SimpleMotor3D>(); _shootScript = GetComponent<EnemyShoot>(); //targetLocation = ((GameObject)Instantiate(AttackLocationPrefab, transform.position, Quaternion.identity)).GetComponent<AttackLocation>(); //targetLocation.available = false; }
// Start is called before the first frame update void Awake() { enemy = GetComponent <RectTransform>(); _anim = GetComponent <Animator>(); shootCs = GetComponent <EnemyShoot>(); col = GetComponent <EnemyCollision>(); }
protected override void OnEnable() { base.OnEnable(); m_agent = this.GetComponentInParent <NavMeshAgent>(); m_enemyAttack = this.GetComponentInParent <EnemyAttack>(); m_enemyShoot = this.GetComponentInParent <EnemyShoot>(); }
void Start() { source = GetComponent <AudioSource>(); EnemyShoot shoot = this.GetComponent <EnemyShoot>(); foreground = GameObject.Find("Foreground").transform; currentBehaviour = BehaviourState.SHOOTING; }
// Use this for initialization void Start() { transformToFollow = GameObject.FindWithTag("Player"); stopThis = GetComponent <MoveForward>(); shootScript = GetComponent <EnemyShoot>(); if (stopThis != null) { originalSpeed = stopThis.moveSpeed; } }
// Use this for initialization void Awake() { rotationSpeed = 5f; _shoot = GetComponentInChildren <EnemyShoot>(); nav = GetComponent <UnityEngine.AI.NavMeshAgent>(); anim = GetComponent <Animator>(); // canSee = GetComponent<CanSeeObject>(); //Initialize State Machine Engine fsm = StateMachine <States> .Initialize(this, States.Idle); }
void Awake() { _patrol = GetComponent <Patrol>(); _anim = GetComponent <Animator>(); _pursue = GetComponent <Pursue>(); canSee = GetComponent <CanSeeObject>(); _shoot = GetComponentInChildren <EnemyShoot>(); //Initialize State Machine Engine fsm = StateMachine <States> .Initialize(this); }
void Awake() { startShoot.enabled = false; // isIn = true; rigid = target.GetComponent <Rigidbody>(); ogRotation = transform.rotation; instance = FindObjectOfType <PlayerMovement>(); currentSpeedz = FindObjectOfType <PlayerMovement>(); shootSpeed = FindObjectOfType <EnemyShoot>(); }
void Awake() { enemyShoot = GetComponentInChildren <EnemyShoot>(); //playerHealth = GameObject.Find ("Player").GetComponent<PlayerHealth> (); enemyState = EnemyState.Enemy_Idle;//敵人最初狀態 isThink = true; nav = GetComponent <NavMeshAgent>(); OriginPoint = transform.position;//敵人最初的位置 animator = GetComponent <Animator>(); }
float timer; //Timer to count for next attacks. void Awake() { //Fill references agent = GetComponent <NavMeshAgent>(); if (target == null) { target = GameObject.FindGameObjectWithTag("Player"); } enemyShoot = gameObject.GetComponent <EnemyShoot>(); //This will find the ranged attack script attached to this object. }
void Start() { _enemyShoot = GetComponent <EnemyShoot>(); _healthComp = GetComponent <HealthComponent>(); _playerTarget = GameObject.Find("Player").transform; _playerMain = GameObject.Find("Player").GetComponent <PlayerMain>(); _rb = GetComponent <Rigidbody2D>(); _startPos = transform.position; stun = false; }
void Awake() { player = GameObject.FindGameObjectWithTag("Player").transform; playerHealth = player.GetComponent <PlayerHealth> (); enemyHealth = GetComponent <EnemyHealth> (); nav = GetComponent <NavMeshAgent> (); anim = GetComponentInChildren <Animator>(); speed = nav.speed; shoot = barrelEnd.GetComponent <EnemyShoot> (); }
void Awake() { enemyShoot = GetComponentInChildren <EnemyShoot> (); // Set up the references. player = GameObject.FindGameObjectWithTag("Player").transform; //playerHealth = player.GetComponent <PlayerHealth> (); //enemyHealth = GetComponent <EnemyHealth> (); nav = GetComponent <NavMeshAgent> (); nav.enabled = false; enemyShoot.enabled = false; }
Transform player; // Reference to the player's position. #endregion Fields #region Methods void Awake() { enemyShoot = GetComponentInChildren <EnemyShoot> (); // Set up the references. player = GameObject.FindGameObjectWithTag ("Player").transform; //playerHealth = player.GetComponent <PlayerHealth> (); //enemyHealth = GetComponent <EnemyHealth> (); nav = GetComponent <NavMeshAgent> (); nav.enabled = false; enemyShoot.enabled = false; }
void Update() { // summon red knight if (_existRedKnight == false && Time.time > _nextTimeToSummonRedKnight) { Summon(RedKnightPrefab, RedKnightSummonPos.position); _existRedKnight = true; } // summon green knight if (_existGreenKnight == false && Time.time > _nextTimeToSummonGreenKnight) { Summon(GreenKnightPrefab, GreenKnightSummonPos.position); _existGreenKnight = true; } // summon black knight if (_existBlackKnight == false && Time.time > _nextTimeToSummonBlackKnight) { Summon(BlackKnightPrefab, BlackKnightSummonPos.position); _existBlackKnight = true; } // check previously summoned enemies if (_existRedKnight == true) { EnemyScout redKnight = GetComponentInChildren <EnemyScout> (); if (redKnight == null) // red knight is gone! { _nextTimeToSummonRedKnight = Time.time + RedKnightSummonInterval; _existRedKnight = false; } // else do nothing } if (_existGreenKnight == true) { EnemyShoot greenKnight = GetComponentInChildren <EnemyShoot> (); if (greenKnight == null) // green knight is gone! { _nextTimeToSummonGreenKnight = Time.time + GreenKnightSummonInterval; _existGreenKnight = false; } // else do nothing } if (_existBlackKnight == true) { EnemyChaseShoot blackKnight = GetComponentInChildren <EnemyChaseShoot> (); if (blackKnight == null) // black knight is gone! { _nextTimeToSummonBlackKnight = Time.time + BlackKnightSummonInterval; _existBlackKnight = false; } // else do nothing } }