コード例 #1
0
    private void FireGun()
    {
        if (gameObject.GetComponent <Energy>().energy - useEnergyPerShoot > 0)
        {
            Ray          ray = Camera.main.ViewportPointToRay(Vector3.one * 0.5f);
            RaycastHit   hitInfo;
            Vector3      direction;
            LineRenderer plasmalr;

            //Draw line
            //LineRenderer plasmalr = plasma.GetComponent<LineRenderer>();
            if (Physics.Raycast(ray, out hitInfo, 100, ~(1 << LayerMask.NameToLayer("isPlayer"))))
            {
                direction = (hitInfo.point - firePoint.position).normalized;
                plasmalr  = Instantiate(lineRend, firePoint.position, Quaternion.LookRotation(direction));
                plasmalr.SetPosition(1, new Vector3(0, 0, hitInfo.distance));

                HP hp = hitInfo.collider.gameObject.GetComponent <HP>();
                if (hp)
                {
                    hp.HPModifier(damage, "plasma");
                }
            }
            else
            {
                plasmalr = Instantiate(lineRend, firePoint.position, Quaternion.LookRotation(ray.direction));
                plasmalr.SetPosition(1, new Vector3(0, 0, 100));
            }

            Destroy(plasmalr.gameObject, 0.3f);
            gameObject.GetComponent <Energy>().UpdateEnergy(useEnergyPerShoot);
        }
    }
コード例 #2
0
    public void Fire(Vector3 player, string newDamage)
    {
        Ray        ray = new Ray(gameObject.transform.position, player - gameObject.transform.position);
        RaycastHit hitInfo;

        // Creates thunder effect
        GameObject newthunder;

        // If it hits something ...
        if (Physics.Raycast(ray, out hitInfo, 100, LayerMask.GetMask("isPlayer", "isGround", "Default")))
        {
            newthunder = Instantiate(thunder, firePoint.position, Quaternion.LookRotation(ray.direction.normalized));
            newthunder.GetComponent <LightningBoltScript>().StartPosition = firePoint.position;
            newthunder.GetComponent <LightningBoltScript>().EndPosition   = hitInfo.point;

            HP hp = hitInfo.collider.gameObject.GetComponent <HP>();
            if (hp)
            {
                hp.HPModifier(5, "electric");
            }
        }
        // If it does not ...
        else
        {
            newthunder = Instantiate(thunder, firePoint.position, Quaternion.LookRotation(ray.direction));
            newthunder.GetComponent <LightningBoltScript>().StartPosition = firePoint.position;
            newthunder.GetComponent <LightningBoltScript>().EndPosition   = ray.direction * 100;
        }

        Destroy(newthunder, 0.1f);
    }
コード例 #3
0
    private void FireGun()
    {
        if (gameObject.GetComponent <Energy>().energy - useEnergyPerShoot > 0)
        {
            // Create ray from the camera, with the directiom from the gun to
            // the end of the ray
            Ray        ray = Camera.main.ViewportPointToRay(Vector3.one * 0.5f);
            Vector3    direction;
            RaycastHit hitInfo;

            // Creates thunder effect
            GameObject newthunder;

            // If it hits something ...
            if (Physics.Raycast(ray, out hitInfo, 100, ~(1 << LayerMask.NameToLayer("isPlayer"))))
            {
                direction = (hitInfo.point - firePoint.position).normalized;

                newthunder = Instantiate(thunder, firePoint.position, Quaternion.LookRotation(direction));
                newthunder.GetComponent <LightningBoltScript>().StartPosition = firePoint.position;
                newthunder.GetComponent <LightningBoltScript>().EndPosition   = hitInfo.point;

                HP hp = hitInfo.collider.gameObject.GetComponent <HP>();
                if (hp)
                {
                    hp.HPModifier(damage, "electric");
                }
            }
            // If it does not ...
            else
            {
                newthunder = Instantiate(thunder, firePoint.position, Quaternion.LookRotation(ray.direction));
                newthunder.GetComponent <LightningBoltScript>().StartPosition = firePoint.position;
                newthunder.GetComponent <LightningBoltScript>().EndPosition   = ray.direction * 100;
                Debug.Log("oof");
            }

            // Removes thunder from the game
            Destroy(newthunder, 0.1f);

            // Removes Energy
            gameObject.GetComponent <Energy>().UpdateEnergy(useEnergyPerShoot);
        }
    }
コード例 #4
0
    public void Fire(Vector3 player)
    {
        Ray        ray = new Ray(gameObject.transform.position, player - gameObject.transform.position);
        RaycastHit hitInfo;

        if (damageType == "plasma")
        {
            LineRenderer plasmalr;

            //Draw line
            //LineRenderer plasmalr = plasma.GetComponent<LineRenderer>();
            if (Physics.Raycast(ray, out hitInfo, 100, LayerMask.GetMask("isPlayer", "isGround", "Default")))
            {
                plasmalr = Instantiate(lineRend, firePoint.position, Quaternion.LookRotation(ray.direction.normalized));
                plasmalr.SetPosition(1, new Vector3(0, 0, hitInfo.distance));

                HP hp = hitInfo.collider.gameObject.GetComponent <HP>();
                if (hp)
                {
                    hp.HPModifier(damage, "plasma");
                }
            }
            else
            {
                plasmalr = Instantiate(lineRend, firePoint.position, Quaternion.LookRotation(ray.direction));
                plasmalr.SetPosition(1, new Vector3(0, 0, 500));
            }

            Destroy(plasmalr.gameObject, 0.3f);
        }
        else if (damageType == "explosionelec")
        {
            // Creates thunder effect
            GameObject newthunder;

            // If it hits something ...
            if (Physics.Raycast(ray, out hitInfo, 100, LayerMask.GetMask("isPlayer", "isGround", "Default")))
            {
                newthunder = Instantiate(thunder, firePoint.position, Quaternion.LookRotation(ray.direction.normalized));
                newthunder.GetComponent <LightningBoltScript>().StartPosition = firePoint.position;
                newthunder.GetComponent <LightningBoltScript>().EndPosition   = hitInfo.point;

                playerInExplosion = Physics.OverlapSphere(hitInfo.point, 2, whatIsPlayer);

                if (playerInExplosion.Length > 0)
                {
                    HP hp = playerInExplosion[0].gameObject.GetComponent <HP>();
                    if (hp)
                    {
                        hp.HPModifier(damage, "plasma");
                    }
                }
            }
            // If it does not ...
            else
            {
                newthunder = Instantiate(thunder, firePoint.position, Quaternion.LookRotation(ray.direction));
                newthunder.GetComponent <LightningBoltScript>().StartPosition = firePoint.position;
                newthunder.GetComponent <LightningBoltScript>().EndPosition   = ray.direction * 100;
            }

            Destroy(newthunder, 0.1f);
        }
        else if (damageType == "explosionplasma")
        {
            LineRenderer plasmalr;

            //Draw line
            //LineRenderer plasmalr = plasma.GetComponent<LineRenderer>();
            if (Physics.Raycast(ray, out hitInfo, 100, LayerMask.GetMask("isPlayer", "isGround", "Default")))
            {
                plasmalr = Instantiate(lineRend, firePoint.position, Quaternion.LookRotation(ray.direction.normalized));
                plasmalr.SetPosition(1, new Vector3(0, 0, hitInfo.distance));
                playerInExplosion = Physics.OverlapSphere(hitInfo.point, 2, whatIsPlayer);

                if (playerInExplosion.Length > 0)
                {
                    HP hp = playerInExplosion[0].gameObject.GetComponent <HP>();
                    if (hp)
                    {
                        hp.HPModifier(damage, "plasma");
                    }
                }
            }
            else
            {
                plasmalr = Instantiate(lineRend, firePoint.position, Quaternion.LookRotation(ray.direction));
                plasmalr.SetPosition(1, new Vector3(0, 0, 500));
            }

            Destroy(plasmalr.gameObject, 0.3f);
        }
        else
        {
            // Creates thunder effect
            GameObject newthunder;

            // If it hits something ...
            if (Physics.Raycast(ray, out hitInfo, 100, LayerMask.GetMask("isPlayer", "isGround", "Default")))
            {
                newthunder = Instantiate(thunder, firePoint.position, Quaternion.LookRotation(ray.direction.normalized));
                newthunder.GetComponent <LightningBoltScript>().StartPosition = firePoint.position;
                newthunder.GetComponent <LightningBoltScript>().EndPosition   = hitInfo.point;

                HP hp = hitInfo.collider.gameObject.GetComponent <HP>();
                if (hp)
                {
                    hp.HPModifier(damage, "electric");
                }
            }
            // If it does not ...
            else
            {
                newthunder = Instantiate(thunder, firePoint.position, Quaternion.LookRotation(ray.direction));
                newthunder.GetComponent <LightningBoltScript>().StartPosition = firePoint.position;
                newthunder.GetComponent <LightningBoltScript>().EndPosition   = ray.direction * 100;
            }

            Destroy(newthunder, 0.1f);
        }
    }