예제 #1
0
파일: Shooter.cs 프로젝트: Kwing95/kabel
    public void DrawLine(Vector2 shotOrigin, Vector2 hitPoint)
    {
        GameObject shotObject = new GameObject();
        AutoVanish vanisher   = shotObject.AddComponent <AutoVanish>();

        vanisher.timeToLive = 0.25f;
        LineRenderer shotLine = shotObject.AddComponent <LineRenderer>();

        shotLine.SetPositions(new Vector3[] { (Vector3)shotOrigin + new Vector3(0, 0, -1), (Vector3)hitPoint + new Vector3(0, 0, -1) });
        shotLine.sortingLayerName = "ForegroundFX";
        shotLine.material         = white;
        shotLine.startWidth       = shotLine.endWidth = 0.07f;
    }
예제 #2
0
    public void FireShot()
    {
        Vector2      direction = target.transform.position - transform.position;
        RaycastHit2D hit       = Physics2D.Raycast(transform.position, direction, 9, mask);
        float        angle     = Vector2.Angle(rotator.FrontOffset(), direction);

        if (hit.collider == null || !hit.collider.CompareTag("Player") || angle > peripheralVision)
        {
            return;
        }

        angle    += Random.Range(0, marginOfError) * (Random.Range(0, 2) == 0 ? 1 : -1);
        direction = Quaternion.AngleAxis(angle, Vector3.forward) * direction;

        hit = Physics2D.Raycast(transform.position, direction, 9, mask);

        if (hit.collider != null && Vector3.Distance(transform.position, target.transform.position) > 1)
        {
            source.PlayOneShot(gunshot);
            Camera.main.GetComponent <Jerk>().Shake(1);
            if (hit.collider.CompareTag("Player"))
            {
                //target.gameObject.GetComponent<ParticleSystem>().Play();
                target.gameObject.GetComponent <Flasher>().Flash(1);
                target.gameObject.GetComponent <Health>().TakeDamage();
            }
            GameObject shotObject = new GameObject();
            AutoVanish vanisher   = shotObject.AddComponent <AutoVanish>();
            vanisher.timeToLive = 0.05f;
            LineRenderer shotLine = shotObject.AddComponent <LineRenderer>();
            shotLine.SetPositions(new Vector3[] { transform.position + new Vector3(0, 0, -1), (Vector3)hit.point + new Vector3(0, 0, -1) });
            shotLine.sortingLayerName = "ForegroundFX";
            shotLine.material         = white;
            shotLine.startWidth       = shotLine.endWidth = 0.03f;
        }
    }