Пример #1
0
    public void BulletScript()
    {
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward * 100000, out hit))
        {
            Shootable ObjectThatWasShot = hit.collider.GetComponent <Shootable>();

            if (ObjectThatWasShot != null)
            {
                ObjectThatWasShot.GetShot();
            }
        }
    }
Пример #2
0
    private void OnTriggerEnter(Collider other)
    {
        // destroy shot if it hits an obstacle
        if (other.GetComponent <Coin>() == null)
        {
            Destroy(gameObject);
        }

        // if shot hits a object within the layer mask destroy the object
        if (((1 << other.gameObject.layer) & LayerDestroy) != 0)
        {
            Shootable shootable = other.GetComponent <Shootable>();
            if (shootable != null)
            {
                shootable.GetShot();
            }
        }
    }