Exemplo n.º 1
0
    private void Awake()
    {
        enemy_Animator       = GetComponent <Animator>();
        enemy_AI             = GetComponent <EnemyAi>();
        All_Colliders        = GetComponentsInChildren <Collider>(true);
        enemy_Destroy_Script = GetComponent <Enemy_Destroy>();

        player = GameObject.Find("PlayerObj").transform;
        agent  = GetComponent <NavMeshAgent>();
    }
Exemplo n.º 2
0
    void Shoot()
    {
        audio_source.clip  = sounds[2];
        audio_source.pitch = Random.Range(0.9f - deepen_shot, 1.1f - deepen_shot);
        audio_source.Play();
        world_pos = c.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, c.nearClipPlane));
        target    = new Vector2(world_pos.x, world_pos.y);
        pos       = new Vector2(transform.position.x, transform.position.y);
        Vector2 dir = (target - pos).normalized;

        shoot_ps.transform.rotation = Quaternion.Euler(new Vector3(0, 0, Mathf.Rad2Deg * Mathf.Atan2(dir.y, dir.x)));
        shoot_ps.Play();



        float n_accuracy = (float)(accuracy * (new System.Random().NextDouble() * new System.Random().NextDouble()));         // Great hack to reduce chance of high direction variation

        dir = new Vector2(dir.x + Random.Range(-n_accuracy, n_accuracy), dir.y + Random.Range(-n_accuracy, n_accuracy));

        RaycastHit2D raycast = Physics2D.Raycast(pos, dir, 100f, ~(1 << 9 | 1 << 2));

        if (raycast.collider)
        {
            explosion_ps.transform.position = raycast.point;
            explosion_ps.Play();


            if (raycast.collider.gameObject.tag == "Enemy")
            {
                Enemy_Destroy  destroy_script = raycast.collider.gameObject.GetComponent <Enemy_Destroy>();
                ParticleSystem ps             = destroy_script.ps;


                //Debug.Log(transform.position.x - raycast.point.x);

                if ((transform.position.x - raycast.point.x) > 0)
                {
                    ps.transform.rotation = Quaternion.Euler(new Vector3(200, 90, 0));
                }
                else
                {
                    ps.transform.rotation = Quaternion.Euler(new Vector3(-20, 90, 0));
                }
                ps.Play();
                if (destroy_script.enabled)
                {
                    gm.Up_the_Ante();
                    audio_source.clip  = sounds[0];
                    audio_source.pitch = Random.Range(0.7f, 1.2f);
                    audio_source.Play();
                }
                else
                {
                    audio_source.clip  = sounds[1];
                    audio_source.pitch = Random.Range(0.7f, 1.2f);
                    audio_source.Play();
                }
                destroy_script.Destroy();

                raycast.collider.GetComponent <Rigidbody2D>().AddForce(dir * shoot_knockback, ForceMode2D.Impulse);
            }
            line_target      = raycast.point;
            draw_line_frames = 2;
        }
        else
        {
            line_target      = new Vector3(pos.x, pos.y, 0) + new Vector3(dir.x, dir.y, 0) * 100;
            draw_line_frames = 2;
        }

        GameObject g = Instantiate(bullet_shell, transform.position, Quaternion.identity, null);

        g.GetComponent <Rigidbody2D>().AddForce(new Vector2(0, 15f));
        g.GetComponent <Rigidbody2D>().AddTorque(Random.Range(-2f, 2f));
        StartCoroutine(c.GetComponent <Camera_Shake>().Shake(1, 3));
    }