示例#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
文件: Shot.cs 项目: zmarx/space-opera
    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();
            }
        }
    }