示例#1
0
    public void Fire(Vector3 position, Vector3 direction, AudioSource audioSource)
    {
        RaycastHit hit;

        //TODO Need to incorporate the accuracy here


        //TODO Maybe i need to used a boxcast of some kind?
        if (Physics.Raycast(position, direction, out hit, range))
        {
            KillableBase killable = hit.transform.GetComponent <KillableBase>();

            //I want to make sure i do negative health (Damage)
            if (killable)
            {
                killable.ChangeHealth(-damage, position);
            }

            //TODO Need some sort of default material to fallback onto
            var temp = hit.transform.GetComponent <Shootable>();
            if (temp)
            {
                temp.Hit(hit);
            }

            //CreateBulletHole(hit.point, hit.normal);
            Debug.DrawLine(position, hit.point, Color.green, 3f);
        }
        else
        {
            Debug.DrawRay(position, direction * range, Color.red, 3f);
        }

        audioSource.PlayOneShot(shootSound);
    }
示例#2
0
    protected override void OnPickedUp(GameObject other)
    {
        KillableBase temp = other.GetComponent <KillableBase>();

        //If the person picking this up can't even use armour, don't try and give them any
        if (temp == null)
        {
            return;
        }

        temp.ChangeHealth(healthAmount);

        base.OnPickedUp(other);
    }