- Home /
Question by
brainkk · Jul 16, 2014 at 12:42 AM ·
destroy object
[JS] Destroy() just don't work :S
Hi everyone i just building a network game and i got a problem i want the character press e to pick up an clone gameobject but its dosen't work there no error.
var testObject : Transform;
private var canHover : boolean = false;
function Update()
{
var fwd = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
if(Physics.Raycast(transform.position, fwd, hit))
{
if(hit.distance <= 5.0 && hit.collider.gameObject.tag == "pickup")
{
canHover = true;
if(Input.GetKeyDown("e"))
{
var cubepos = transform.position + (transform.forward * 2);
var clonecube=Instantiate(testObject,cubepos,Quaternion.identity);
Destroy(clonecube.gameObject);
}
}
else
{
canHover = false;
}
}
}
function OnGUI()
{
if(canHover == true){
GUI.Box(Rect(Screen.width / 2 - 100, Screen.height / 2 - 100, 150, 20), "Destroy");
}
}
Comment
What happens when you try to pick up the cube?
As far as I can make sense of your script, you create a clone on line 19... then immediately destroy it on line 20. That doesn't seem to make much sense.
Not sure what you are trying to do here. You create 'clonecube' on line 19 but Destory() it one line later. $$anonymous$$aybe you wanted to destory 'hit.collider.gameObject' ins$$anonymous$$d?
Your answer
Follow this Question
Related Questions
Script from JS to C# 1 Answer
Array problem,different result 1 Answer
Teleport Charactor 2 Answers
GUI text Issues 1 Answer