My script is supposed to function as whenever the object “Drawing1” is clicked, it is supposed to be destroyed, but whenever I click, it remains there. Any advice? Thanks in advance. :slight_smile:

#pragma strict
var range : float = 500;
var wasClicked = false;
var Char : Transform;
var DrawingGet : GameObject;

function OnMouseUp(){
    wasClicked = true;
}

function Update () {
	var Char = GameObject.Find("Char");
    var dist = Vector3.Distance(transform.position, Char.transform.position);
    if(wasClicked == true && dist <= range){
       Destroy(gameObject);
    }
}

Couple issues with your script. I’m assuming this script is attached to each object you want to destroy, and not the player. I’m assuming the Char transform is the player. You only need to get Char in start function, not all the time, in Update. You defined dist initially AND in update, you don’t need to use “var” if you already have defined a variable. I would also Debug the distance to make sure it is actually below the range. You were also trying to convert a Transform to a GameObject. Try This…

#pragma strict

var range : float = 500;
var wasClicked = false;
var Char : GameObject;
var DrawingGet : GameObject;
var dist : float;

function Start()
{    
    Char = GameObject.Find("Char");
}

function OnMouseUp()
{
    wasClicked = true;
}

function Update () 
{
    Debug.Log(dist);
    dist = Vector3.Distance(transform.position, Char.transform.position);
    if(wasClicked && dist <= range)
       Destroy(gameObject);
}