Ejemplo n.º 1
0
    void Shoot()
    {
        muzzleFlash.Play();
        RaycastHit hit;

        if (Physics.Raycast(FpsCam.transform.position, FpsCam.transform.forward, out hit, range))
        {
            Debug.Log(hit.transform.name);
            if (hit.transform.name == "cible(Clone)")
            {
                GameObject.Find("cible(Clone)").GetComponent <cibleBehavior>().gethit = true;
            }

            target Target = hit.transform.GetComponent <target>();
            if (Target != null)
            {
                Target.TakeDamage(damage);
            }

            if (hit.rigidbody != null)
            {
                hit.rigidbody.AddForce(-hit.normal * impactForce);
            }
        }
    }
Ejemplo n.º 2
0
    void Update()
    {
        if (isDestinationReached())
        {
            Destroy(gameObject);
            return;
        }

        transform.Translate(Vector3.forward * speed * Time.deltaTime);

        if (destination != Vector3.zero)
        {
            return;
        }

        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit, 5f))
        {
            CheckDistructable(hit);

            target target = hit.transform.GetComponent <target>();
            if (target != null)
            {
                target.TakeDamage(damage);
            }
        }
        if (hit.rigidbody != null)
        {
            hit.rigidbody.AddForce(-hit.normal * impactforces);
        }
    }
Ejemplo n.º 3
0
    void shoot()
    {
        //var newbullet = Instantiate(bulletPrefab, (transform.position + transform.up * 1.5f + transform.forward), Quaternion.identity);
        // Destroy(newbullet, 2f);
        shaker.Triggershake();
        muzzleFlash.Play();

        currentAmmo--;
        ammo--;


        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            Debug.Log(hit.transform.name);

            target target = hit.transform.GetComponent <target>();
            if (target != null)
            {
                target.TakeDamage(damage);
            }

            if (hit.rigidbody != null)
            {
                hit.rigidbody.AddForce(-hit.normal * impactForce);
            }

            GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
            Destroy(impactGO, 2f);
        }
    }
Ejemplo n.º 4
0
    void shoot()
    {
        muzzleFlash.Play();

        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            Debug.Log(hit.transform.name);

            target target = hit.transform.GetComponent <target> ();

            if (target != null)
            {
                target.TakeDamage(damage);
            }

            if (hit.rigidbody != null)
            {
                hit.rigidbody.AddForce(-hit.normal * impactForce);
            }

            GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
            Destroy(impactGO, 2f);
        }
    }
Ejemplo n.º 5
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space) && Time.time > nextFire && !is_fire)
        {
            is_fire = true;
            anim.Play("recul");


            audio_fire.enabled = false;

            first_collider.GetComponent <BoxCollider>().enabled = false;

            nextFire = Time.time + fireRate;

            StartCoroutine(ShotEffect());

            Vector3    rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));
            RaycastHit hit;

            laserLine.SetPosition(0, gunEnd.position);

            if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange))
            {
                laserLine.SetPosition(1, hit.point);

                target      Target          = hit.transform.GetComponent <target>();
                BoxCollider Target_collider = hit.transform.GetComponent <BoxCollider>();
                if (Target != null && !Target_collider.isTrigger)
                {
                    Target.TakeDamage(gunDamage);
                    GameObject impact = Instantiate(ImpactEffect, hit.point, Quaternion.LookRotation(hit.normal));
                    Destroy(impact, 0.5f);
                }

                if (hit.rigidbody != null)
                {
                    hit.rigidbody.AddForce(-hit.normal * hitForce);
                }
                else
                {
                    laserLine.SetPosition(1, rayOrigin + (fpsCam.transform.forward * weaponRange));
                }
            }

            first_collider.GetComponent <BoxCollider>().enabled = true;
        }

        if (is_fire)
        {
            is_fire_time += Time.deltaTime;
            if (is_fire_time > anim.clip.length)
            {
                is_fire      = false;
                is_fire_time = 0;
            }
        }
    }
Ejemplo n.º 6
0
    private void OnTriggerEnter(Collider other)
    {
        target tar = other.GetComponent <target>();

        if (tar != null)
        {
            tar.TakeDamage(damage);
        }

        Destroy(gameObject);
    }
Ejemplo n.º 7
0
    void Shoot()
    {
        LayerMask    mask = LayerMask.GetMask("Terrain", "Enemy");
        RaycastHit2D hit  = Physics2D.Raycast(fireStart.position, fireStart.up, range, mask);

        if (hit.collider != null)
        {
            target gametarget = hit.transform.GetComponent <target>();
            if (gametarget != null)
            {
                gametarget.TakeDamage(damage);
            }
        }
    }
Ejemplo n.º 8
0
    void shoot()
    {
        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            Debug.Log(hit.transform.name);

            target target = hit.transform.GetComponent <target>();
            if (transform != null)
            {
                target.TakeDamage(damage);
            }
        }
    }
Ejemplo n.º 9
0
    void Shoot()
    {
        muzzleFLash.Play();
        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            target target = hit.transform.GetComponent <target>();
            if (target != null)
            {
                target.TakeDamage(damage);
            }

            GameObject impactGo = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
            Destroy(impactGo, 2f);
        }
    }
Ejemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButton("Fire1"))
        {
            Shoot();
        }

        void Shoot()
        {
            RaycastHit hit;

            if (Physics.Raycast(fpscam.transform.position, fpscam.transform.forward, out hit, range))
            {
                target target = hit.transform.GetComponent <target>();
                if (target != null)
                {
                    target.TakeDamage(damage);
                }
            }
        }
    }
Ejemplo n.º 11
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            shoot();
        }

        void shoot()
        {
            shot.Play();
            RaycastHit hit;

            if (Physics.Raycast(camera.position, camera.forward, out hit, maxDistance))
            {
                target t = hit.transform.GetComponent <target>();
                if (t != null)
                {
                    t.TakeDamage(10f);
                }
            }
        }
    }
Ejemplo n.º 12
0
    void Shoot()
    {
        myAnim.SetTrigger("recoil");
        muzzleflash.Play();
        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            ;
        }
        {
            Debug.Log(hit.transform.name);
            target target = hit.transform.GetComponent <target>();
            if (target != null)
            {
                target.TakeDamage(damage);
            }
            Ray ray = new Ray(transform.position, transform.forward);
            line.SetPosition(0, ray.origin);
            line.SetPosition(1, ray.GetPoint(100));
        }
    }
Ejemplo n.º 13
0
    void shoot()
    {
        p.Play();
        RaycastHit hit;

        if (Physics.Raycast(fps.transform.position, fps.transform.forward, out hit, range))
        {
            Debug.Log(hit.transform.name);
            target t = hit.transform.GetComponent <target>();
            if (t != null)
            {
                t.TakeDamage(damage);
            }
            if (hit.rigidbody != null)
            {
                hit.rigidbody.AddExplosionForce(5f, hit.point, 1f);
            }
        }
        GameObject eff = Instantiate(impacteff, hit.point, Quaternion.LookRotation(hit.normal));

        Destroy(eff, 2f);
    }
Ejemplo n.º 14
0
    private void Shoot()
    {
        shot.Play();
        RaycastHit hitInfo;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hitInfo, distance))
        {
            Debug.Log(hitInfo.transform.name);

            target tar = hitInfo.transform.GetComponent <target>();
            if (tar != null)
            {
                tar.TakeDamage(damage);
            }

            if (hitInfo.rigidbody != null)
            {
                hitInfo.rigidbody.AddForce(-hitInfo.normal * impactForce);
            }

            GameObject impactGO = Instantiate(impactEffect, hitInfo.point, Quaternion.LookRotation(hitInfo.normal));
            Destroy(impactGO, 2f);
        }
    }