- Home /
Collestion of objects
Hello,How to make object when u click on him it vanishes and on screen it says like 1/10 items collected?
Answer by Seth-Bergman · Oct 14, 2012 at 08:36 AM
please don't create new answers as comments, use the comment instead..
as for your question, you need to set up a simple script to keep track of the number of your items collected, and display the total. Here's a simple example:
static var itemsCollected : int;
var display : boolean = false;
function OnMouseDown(){
if(!display){
itemsCollected += 1;
display = true;
var mesh : MeshRenderer = GetComponent(MeshRenderer);
mesh.enabled = false;
yield WaitForSeconds(5);
Destroy(gameObject);
}
}
function OnGUI(){
if(display)
GUI.Label(Rect(Screen.width/2 - 60,20, 120, 20), "Items Collected: " + itemsCollected);
}
just attach this javascript to your prefab, and it should do what you ask..
EDIT: updated this slightly, as the previous version could cause unwanted issues..
Answer by Perox · Oct 14, 2012 at 08:12 AM
sry mate but I'm not very good at this... Should i write something like this for "OnMouseDown"
// Loads the level named "SomeLevel" as a response // to the user clicking on the object
function OnMouseDown () { Application.LoadLevel ("SomeLevel"); }
Your answer
Follow this Question
Related Questions
How to pick up an object and inspect that object by rotating it!(HELP NEEDED) 0 Answers
Pick up objects to destroy one object. 1 Answer
How to pick up an object using left mouse button 2 Answers
How to make a character collect items? 4 Answers
How do you access the transform component of an object in another class? 1 Answer