Collect papers script
Hi, I'd like som help with my script. I want to be able to click on a paper and collect it, and I've watched several videos but they are either 25 minutes long or not exactly what i want. Do I need to say I'm a newbie and know little to nothing about coding or coding? And sorry if the english is bad, I'm from Sweden.
How do I transform this script from "collide to delete/collect" into a "click to delete/collect"? I've tried a few times but I can't get it to work.
var Paper : int = 0;
var paperToWin : int = 30; //number to win!
function OnTriggerEnter( other : Collider )
{
if (other.gameObject.tag == "Paper")
{
Paper += 1;
Debug.Log("A paper was picked up. Total papers = " + Paper);
Destroy(other.gameObject);
}
}
function OnGUI()
{
if (Paper < paperToWin)
{
GUI.Box(Rect((Screen.width/2)-100, 10, 200, 35), "" + Paper + " Papers");
}
else
{
GUI.Box(Rect((Screen.width/2)-100, 10, 200, 35), "All Papers Collected!");
}
}
Answer by UnityCoach · Mar 11, 2017 at 07:23 PM
Hey there. I can only advise to learn coding for future development, as what you want to do isn't just a few scripts, you'll need to figure an "architecture" that suits your objectives.
Anyway, to give you a little help on this one, OnTriggerEnter is one of the "messages" that every MonoBehaviour (script component class) receives at times. This one tells that a collider entered the trigger collider that is on the object.
OnMouseDown, OnMouseUp, OnMouseUpAsButton are other message. This should be enough to help you do what you want.
Should you want to invest in learning, here's a full training course I'm working on.