- Home /
Remove object with specific object
Hi! I have script that makes you remove specific objects when clicking on them, but only if if has the tag "plank". The thing I want to do is to pickup a crowbar and then have a script that tells the game "If you have a crowbar in your hand and left click on a wooden plank, then remove it. If you only use your hand, nothing happens".
Does anyone know how to make that? Maybe this question needs to be post on the "Forums" tab?
var plank : AudioClip;
function Update ()
{
if ( Input.GetMouseButtonDown(0) )
{
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, hit, 15.0))
{
if(hit.collider.gameObject.tag=="plank")
{
AudioSource.PlayClipAtPoint(plank, transform.position);
Destroy(hit.collider.gameObject);
}
}
}
}
Answer by chronicfail · Jul 31, 2013 at 06:40 PM
To pickup the crow bar there are a lot of solutions, but however you do it, you could make a "hasCrowbar" variable, made true when the crowbar is picked up. On the "if(hit.collider.gameObject.tag=="plank")" change it to "if(hit.collider.gameObject.tag=="plank"&&hasCrowbar)"