- Home /
Collect and through
Hi there and thanks for looking the problem i am having is i am trying to write a script so that i can collect an object so the script counts how much of that thing i have then when i through it it deducts it from my script also with a gui write so that it adds it in the gui and subtracts it but i don't know how to go about writing that i thought maybe i could use the fps ammo count but doesnt seem to work.
This is the last thing i need for my game mechanics i have got my AI scipts working lives and hits and no this isn't a tornado twins type game lol usually have a scripter but he is on holiday please help guys
if you need any more info please help as this assignment needs to be handed in in three days
Answer by Jesse Anders · Apr 18, 2011 at 02:02 PM
Why no capitalization or punctuation? :|
(Well, to be fair, there is a capital letter at the beginning of the first paragraph and a period at the end of it, but nevertheless it's still a little difficult to read ;)
Anyway, here are some suggestions based on what I was able to glean from your post.
Look into colliders, triggers, and callback functions such as OnTriggerEnter() for determining when a 'pick-up' item has been collided with.
Store the number of items collected in a variable of type 'int'.
In an OnGUI() function associated with the same script, use GUI.Label() or GUILayout.Label() to display the item count. You can use int.ToString() to convert the count to string form for display purposes.
You mentioned deducting and subtracting, so it sounds like there's more going on than simply accumulating items. If you need more help though, we might need some more details about what you're trying to do.
Thanks. What i am trying to do is. When the player collides with an object (Let's say a bottle). A script counts how many bottles i have and gives me points for collecting the bottle. Now when i throw the bottle it deducts that from how many i have collected and when i am at 0 no more bottles can be thrown. Also when i collect a bottle i would like it so that there is some picture at the top left of my screen that displays how much i have left not just text but with images
What you describe has about 4 or 5 different aspects to it (picking up items, keeping track of them, throwing items, displaying the current number of items graphically, etc.). What I'd recommend is tackling one problem at a time, and then asking about each problem separately here or on the forums as needed. For example, you could start with the 'picking up an item' part (for which you'd probably use a trigger collider and OnTriggerEnter()). If you have problems with that part, I'd recommend posting to the forums (it might be a little easier for people to help there).
Your answer

Follow this Question
Related Questions
How to increase score on hit 0 Answers
adding ammo count 2 Answers
make it create GUI copy per count. 0 Answers
Help for shots in a script 2 Answers
Count objects with a certain tag and display number on GUI 1 Answer