Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        cooldownRemaining -= Time.deltaTime;
        if (Input.GetMouseButton(0) && cooldownRemaining <= 0)
        {
            cooldownRemaining = cooldown;

            Ray        ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
            RaycastHit hitInfo;


            if (Physics.Raycast(ray, out hitInfo, range))
            {
                Vector3    hitPoint = hitInfo.point;
                GameObject go       = hitInfo.collider.gameObject;
                Debug.Log("Hit Object:" + go.name);
                Debug.Log("Hit Point:  " + hitPoint);


                hasHealth h = go.GetComponent <hasHealth>();
                if (h != null)
                {
                    h.RecieveDamage(damage);
                }

                if (debrisPrefab != null)
                {
                    Instantiate(debrisPrefab, hitPoint, Quaternion.identity);
                }
            }
        }
    }
Exemple #2
0
    void Detonate()
    {
        Vector3 explosionPoint = transform.position;

        GameObject expl = Instantiate(explosionPart, transform.position, Quaternion.identity) as GameObject;

        Destroy(gameObject);

        Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius);

        foreach (Collider c in colliders)                                               //loop for arrays in Collider[]
        {
            hasHealth h = c.GetComponent <hasHealth>();
            if (h != null)
            {
                float dist = Vector3.Distance(explosionPoint, c.transform.position);                  //gets distance between two

                if (dist <= explosionRadius)
                {
                    Debug.Log("Distance Between: " + dist);
                    float damageRatio = 1f - (dist / explosionRadius);              //Takes some damage in radius of explosion, sets damage curve

                    h.RecieveDamage(damage * damageRatio);
                }
            }
        }
    }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown("t"))
        {
            if (greNum == 0)
            {
                greNum++;
            }
            else
            {
                greNum--;
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
            RaycastHit hitInfo;              //Passing as output parameter

            //Makes bullet object


            if (Physics.Raycast(ray, out hitInfo, gunRange))                  // returns t/f
            {
                Vector3    hitPoint = hitInfo.point;
                GameObject go       = hitInfo.collider.gameObject;
                Debug.Log("Hit Object:" + go.name);                   //will tell us what we hit
                Debug.Log("Hit Point:" + hitPoint);                   //will tell us where we hit

                hasHealth h = go.GetComponent <hasHealth>();

                if (h != null)
                {
                    h.RecieveDamage(damage);
                }

                if (debrisPrefab != null)
                {
                    Instantiate(debrisPrefab, hitPoint, Quaternion.identity);
                }
            }
            Camera     cam       = Camera.main;
            GameObject theBullet = (GameObject)Instantiate(bullet_Prefab, cam.transform.position + cam.transform.forward, cam.transform.rotation);
            theBullet.GetComponent <Rigidbody>().AddForce(cam.transform.forward * bulletImpulse, ForceMode.Impulse);
        }
        if (Input.GetMouseButtonDown(1))
        {
            Camera     cam          = Camera.main;
            GameObject stickyBullet = (GameObject)Instantiate(stickyBullet_Prefab, cam.transform.position + cam.transform.forward, cam.transform.rotation);
            stickyBullet.GetComponent <Rigidbody>().AddForce(cam.transform.forward * stickyBulletImpulse, ForceMode.Impulse);
        }

        if (Input.GetKeyDown("g"))
        {
            throwGrenade(greNum);
        }
    }