The question is answered, right answer was accepted
';' expected. Insert a semicolon at the end. Already have one
Not sure what is happening, here's my script. Happen on "float dist" line.
#pragma strict
var item : GameObject;
function Start ()
{
gameObject.transform.localRotation = Quaternion.Euler(0,0,0);
}
function Update()
{
if(Input.GetKeyDown(KeyCode.E))
{
float dist = Vector3.Dist(object.positon,player.position);
if(dist<minDist)
{
pickup();
}
}
}
Try :
float dist = Vector3.Dist(gameObject.transform.positon,player.transform.position);
Just tried. Nope the error still comes up, I'm not sure what I have done wrong
Answer by Hellium · Nov 26, 2017 at 11:41 AM
#pragma strict
var item : GameObject;
var player : GameObject;
var minDist : float;
function Start ()
{
gameObject.transform.localRotation = Quaternion.Euler(0,0,0);
}
function Update()
{
if(Input.GetKeyDown(KeyCode.E))
{
var dist : float = Vector3.Distance(transform.position,player.transform.position);
if(dist<minDist)
{
pickup();
}
}
}
function pickup()
{
// ....
}
If you still have the message in your IDE (like me), but no error in Unity, it's fine.
Thank you for this. This fixes the error. The only problem I am now having is I'm trying to add a "Destory(gameObject)" part to the end so that once the function is called the item will be destroyed i.e the player picking it up.
Simply put Destroy( gameObject );
inside the pickup
function
I just added it in and still does not destroy the game object. I'm really sorry for see$$anonymous$$g like I have no idea what I'm doing
Okay just got a script working. Thank you for the help!