Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
        {
            nextFire = Time.time + fireTimer;
            System.Console.Out.WriteLine("hack");


            others = Physics.OverlapBox(Collider.transform.position, new Vector3(3, 3, 3));

            foreach (Collider c in others)
            {
                if (c.gameObject.tag == "Attackable")
                {
                    //c.gameObject.GetComponent<Rigidbody>().AddForce(fpsCam.transform.forward * hitForce);

                    RespawnScript rs = c.gameObject.GetComponent <RespawnScript>();
                    if (rs != null)
                    {
                        col.Collect(rs.type);
                        this.StartCoroutine(rs.RespawnEffect());
                        rs.gameObject.SetActive(false);
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        ammunitionText.text = "Ammunition: " + ammunition.ToString();


        if (Input.GetButtonDown("Fire1") && Time.time > nextFire && ammunition > 0)
        {
            ammunition--;
            nextFire = Time.time + fireTimer;
            StartCoroutine(ShotEffect());
            System.Console.WriteLine("shoot");

            Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));
            laserLine.SetPosition(0, gunEnd.position);
            RaycastHit hit;
            if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange))
            {
                laserLine.SetPosition(1, hit.point);
                if (hit.rigidbody != null)
                {
                    hit.rigidbody.AddForce(-hit.normal * hitForce);
                    RespawnScript rs = hit.transform.gameObject.GetComponent <RespawnScript>();
                    if (rs != null)
                    {
                        col.Collect(rs.type);
                        this.StartCoroutine(rs.RespawnEffect());
                        rs.gameObject.SetActive(false);
                    }
                }
            }
            else
            {
                laserLine.SetPosition(1, rayOrigin + (fpsCam.transform.forward * weaponRange));
            }
            laserLine.SetPosition(1, hit.point);
        }
    }