// Use this for initialization
 void Start()
 {
     _body       = GetComponent <Rigidbody2D>();
     _anim       = GetComponent <Animator>();
     _coll       = GetComponent <CapsuleCollider2D>();
     _controller = GetComponent <EnemyControllerScript>();
 }
Esempio n. 2
0
    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;
 }
Esempio n. 4
0
 void OnLevelWasLoaded()
 {
     if (Application.loadedLevel == 1)
     {
         eControlScript = GameObject.Find("EnemyControl").GetComponent<EnemyControllerScript>();
         spawnScript = GameObject.Find("EnemyControl").GetComponent<Spawn>();
         timeAtLevelLoad = Time.timeSinceLevelLoad;
     }
 }
Esempio n. 5
0
    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);
        }
    }
Esempio n. 6
0
    // 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;
    }
Esempio n. 7
0
    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));
    }
Esempio n. 8
0
    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);
        }
    }
Esempio n. 9
0
    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>();
    }
Esempio n. 10
0
    // 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;
                }
            }
        }
    }
Esempio n. 11
0
 // Use this for initialization
 void Awake()
 {
     ecs = transform.parent.GetComponent <EnemyControllerScript> ();
 }
Esempio n. 12
0
 void Start()
 {
     parentScript = transform.parent.GetComponent<EnemyControllerScript>();
     Physics.IgnoreCollision(collider, GameObject.FindGameObjectWithTag("Player").collider);
 }
Esempio n. 13
0
 public abstract void Move(EnemyControllerScript ecs);
Esempio n. 14
0
 // 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();
 }
Esempio n. 15
0
    // 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;
    }
Esempio n. 16
0
    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);
    }