Exemple #1
0
    public bool Shoot(GameObject camera, Enemy shooter)
    {
        if (!IsValid || CurAmmo == 0)
        {
            return(false);
        }
        GameObject newGrenade = MonoBehaviour.Instantiate(grenade.instantiableGrenade, camera.transform.position, camera.transform.rotation) as GameObject;

        newGrenade = grenade.convert(newGrenade);
        newGrenade.transform.parent = camera.transform;
        newGrenade.transform.Translate(spawnPos);
        if (newGrenade.GetComponent <Rigidbody>())
        {
            newGrenade.GetComponent <Rigidbody>().AddRelativeForce(0, 0, ShotForce);
        }
        else
        {
            newGrenade.AddComponent <Rigidbody>();
            newGrenade.GetComponent <Rigidbody>().AddRelativeForce(0, 0, ShotForce);
        }

        if (blowback)
        {
            Debug.Log("Performing blowback Raycast...");
            RaycastHit hit;
            if (Physics.Raycast(blowbackOutput, VectorF.RotateY(((Weapon)this).mainObject.transform.eulerAngles, 180), out hit, blowbackDistance))
            {
                GameObject g = hit.transform.gameObject;
                Debug.Log("Hit " + g.name);
                if (g.GetComponent <EnemyHealth>() != null)
                {
                    Debug.Log("Hit an enemy, killing it...");
                    g.GetComponent <EnemyHealth>().damage((hit.distance / blowbackDistance) * maxBlowbackDamage, DamageCause.Blowback);
                }
                else
                {
                    Debug.Log("Hit a wall, killing you...");
                    ((Weapon)this).mainObject.transform.parent.gameObject.GetComponent <Health>().
                    Damage((hit.distance / blowbackDistance) * maxBlowbackDamage, DamageCause.Blowback);
                }
            }
            else
            {
                Debug.Log("Didn't hit anything.");
            }
        }

        newGrenade.transform.parent = null;
        CurAmmo -= 1;
        return(true);
    }