i need help picking up objects in unity. i have found a pick up script but i dont know were to attach it to. here is the script:
private var isHighlighted : boolean = false;
private var gameCharacter : Transform;
private var distance : float;
function Start() {
gameCharacter = GameObject.Find("First Person Controller").GetComponent(Transform);
}
function OnMouseEnter() {
if(distance <= 4.0) {
CreateInfoName();
renderer.material.color = Color.red;
isHighlighted = true;
}
}
function OnMouseExit() {
renderer.material.color = Color.white;
Destroy(GameObject.Find("infoName"));
isHighlighted = false;
}
function Update () {
distance = Mathf.Sqrt((gameCharacter.position - transform.position).sqrMagnitude);
if(Input.GetKey("e") && isHighlighted == true){
Destroy(gameObject);
}
}
function CreateInfoName(){
var infoName = new GameObject("infoName");
infoName.AddComponent(GUIText);
infoName.GetComponent(GUIText).text = gameObject.name;
infoName.transform.position = Vector3(0.5, 0.5, 0);
infoName.GetComponent(GUIText).alignment = TextAlignment.Center;
infoName.GetComponent(GUIText).anchor = TextAnchor.LowerCenter;
infoName.GetComponent(GUIText).pixelOffset = Vector2 (0, 25);
}
can anyone help me figure this out please