// Use this for initialization void Start() { _body = GetComponent <Rigidbody2D>(); _anim = GetComponent <Animator>(); _coll = GetComponent <CapsuleCollider2D>(); _controller = GetComponent <EnemyControllerScript>(); }
void OnTriggerExit(Collider collider) { if (collider.tag == "Enemy") { if (this.target == collider.gameObject.GetComponent <EnemyControllerScript>()) { this.target = null; } this.enemyInVision.Remove(collider.gameObject.GetComponent <EnemyControllerScript>()); GameObject[] gos = GameObject.FindGameObjectsWithTag("Cop"); bool find = false; foreach (GameObject go in gos) { PolicemanScript ps = go.GetComponent <PolicemanScript>(); if (ps.enemyInVision.Contains(collider.gameObject.GetComponent <EnemyControllerScript>())) { find = true; break; } } if (!find && collider.gameObject.GetComponent <EnemyControllerScript>().Pv > 0) { collider.gameObject.renderer.enabled = false; } } }
// Use this for initialization void Start() { _controller = GetComponent <EnemyControllerScript>(); _anim = GetComponent <Animator>(); _col = GetComponent <Collider2D>(); _hitbox = transform.Find("Hitbox").gameObject; fullHealth = _controller.Health; }
void OnLevelWasLoaded() { if (Application.loadedLevel == 1) { eControlScript = GameObject.Find("EnemyControl").GetComponent<EnemyControllerScript>(); spawnScript = GameObject.Find("EnemyControl").GetComponent<Spawn>(); timeAtLevelLoad = Time.timeSinceLevelLoad; } }
public override void Move(EnemyControllerScript ecs) { float h = ecs.facingRight ? 1.0f : -1.0f; if (Mathf.Abs(ecs.rb2d.velocity.y) == 0) { ecs.rb2d.AddForce(new Vector2(h * forceX, forceY), ForceMode2D.Impulse); } }
// Use this for initialization void Start() { Debug.Log("Chasing script started"); _startPosition = transform.position; _controller = GetComponent <EnemyControllerScript>(); _body = GetComponent <Rigidbody2D>(); _anim = GetComponent <Animator>(); Player = PlayerManager.instance.Player.transform; }
public override void Move(EnemyControllerScript ecs) { float horizontal = ecs.facingRight ? 1.0f : -1.0f; ecs.rb2d.AddForce(new Vector2(horizontal * ecs.acceleration, 0), ForceMode2D.Force); horizontal = ecs.health < 2 ? horizontal * 0.2f : horizontal; if (Mathf.Abs(ecs.rb2d.velocity.x) > ecs.maxSpeed) { ecs.rb2d.velocity = new Vector2(ecs.maxSpeed * horizontal, ecs.rb2d.velocity.y); } anim.SetFloat("speed", Mathf.Abs(horizontal)); }
public override void Move(EnemyControllerScript ecs) { float h = ecs.facingRight ? 1.0f : -1.0f; ecs.rb2d.AddForce(new Vector2(h * ecs.acceleration, 0), ForceMode2D.Force); if (ecs.rb2d.velocity.x > ecs.maxSpeed) { ecs.rb2d.velocity = new Vector2(ecs.maxSpeed, ecs.rb2d.velocity.y); } else if (ecs.rb2d.velocity.x < -ecs.maxSpeed) { ecs.rb2d.velocity = new Vector2(-ecs.maxSpeed, ecs.rb2d.velocity.y); } }
void Awake() { previousState = currentState = State.Idle; alertTime = 0; behaviorSprite = new GameObject(); spriteRenderer = behaviorSprite.AddComponent <SpriteRenderer>(); behaviorSprite.transform.name = "BehaviorSprite"; behaviorSprite.transform.parent = gameObject.transform; behaviorSprite.transform.position = stateSpriteOffset + gameObject.transform.position; sightScript = GetComponent <VisionConeScript>(); enemyControllerScript = GetComponent <EnemyControllerScript>(); animator = GetComponent <Animator>(); }
// Update is called once per frame void Update() { if (GameManagerScript.gameState == GameManagerScript.GameState.START && this.Pv > 0 && this.executeActions) { if (this.target == null) { if (this.enemyInVision.Count > 0) { this.target = this.enemyInVision[0]; } } if (this.target) { if (this.target.Pv > 0) { if (Time.time >= this.previousTime + this.attackSpeed) { //Instanciate the bullet GameObject go = Instantiate(this.BulletPrefab, this.transform.position, Quaternion.identity) as GameObject; go.transform.LookAt(this.target.transform); //if (!enemy.isSeeingPoliceman(this)) //{ // go.GetComponent<BulletScript>().Damage = enemy.Pv; //} this.previousTime = Time.time; } } else { this.enemyInVision.Remove(this.target); this.target = null; } } } }
// Use this for initialization void Awake() { ecs = transform.parent.GetComponent <EnemyControllerScript> (); }
void Start() { parentScript = transform.parent.GetComponent<EnemyControllerScript>(); Physics.IgnoreCollision(collider, GameObject.FindGameObjectWithTag("Player").collider); }
public abstract void Move(EnemyControllerScript ecs);
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { enemyController = animator.GetComponentInParent <EnemyControllerScript>(); enemyController.CastAttack(); }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { // //} // OnStateExit is called when a transition ends and the state machine finishes evaluating this state override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { enemyController = animator.GetComponentInParent <EnemyControllerScript>(); enemyController.StopAttack(); enemyController.State = Assets.Scripts.EnemyState.CHASING; }
public override void Move(EnemyControllerScript ecs) { float h = ecs.facingRight ? 1.0f : -1.0f; transform.position += new Vector3(0.1f * h, Mathf.PingPong(Time.time, amplitude) - amplitude / 2.0f, 0); }