Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by metallica6474 · Apr 29, 2016 at 07:36 PM · animationinventorytriggering animation box collider

How can I make the game recognize when I have 60 rocks in my inventory.

Alright so in my game you are stranded on an island. Your objective is to find 60 rocks, and then return to a point on the island, once that happens I want an animation to kick in zooming out of the islands and the rocks will be arranged to say "S.O.S", but how do I do that? How do I have the game recognize that I have 60 rocks in my inventory? How do I have the game recognize when i'm in a certain spot with 60 rocks in my inventory, and when that happens have the animation kick in? Thanks. Also, the script i'm using for my inventory is Inventory Master.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image metallica6474 · Apr 29, 2016 at 05:24 PM 0
Share

Oh, and if you respond with a semi complicated answer, could you please just tell me what to google and if it should help me or not, i'm VERY new to Unity and Scripting.

avatar image gjf · Apr 29, 2016 at 07:42 PM 0
Share

i know zero knowledge of Inventory $$anonymous$$aster and no intention to change that, so the following answers may not be easily applicable ;)

"How do I have the game recognize that I have 60 rocks in my inventory?" maintain a counter of the collected rocks.

"How do I have the game recognize when i'm in a certain spot with 60 rocks in my inventory" when you get to that spot (probably using a collider of some sort), simply check the counter

"...when that happens have the animation kick in?" if you're at the location and the count is sufficient, play the animation.

if you need to learn how to do those things, there are many tutorials for colliders and animation. the counting stuff is beginners stuff and, since it sounds like you have some experience, it should be straightforward for you ;)

in future, try to ask a single question at a time... you're more likely to get specific answers. asking unclear, vague or multiple-part questions lessens the likelihood of that! check the faq for guidelines and advice on what constitutes a good question.

avatar image metallica6474 gjf · May 04, 2016 at 05:11 PM 0
Share

Alright, will do. Thanks for the help!

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by tanoshimi · Apr 29, 2016 at 07:54 PM

Add a Collider marked as "Is Trigger" at the spot on the island you need to return to. Then add a script with the following function attached to it.

 [Tooltip("Drag your player's inventory into this slot")]
 [SerializeField]
 private Inventory playerInventory;
 
 [Tooltip("Set this to the ID of the stone in your inventory system")]
 [SerializeField]
 private int stoneID;
 
 // Something entered the spot...
 void OnTriggerEnter(Collider other) {

   // .. was it the player?
   if (other.CompareTag("Player") ) {

     // If so, rummage through their inventory
     List<Item> items = playerInventory.getItemList();

     // and count up how many stones they have
     int numStones = 0;
     for(int i=0; i<items.Count; i++)  { if (items[i].itemID == stoneID) numStones++; }

     // Do they have enough?
     if(numStones >= 60) { SOSAnimation.Play(); }
   }
 }


Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image metallica6474 · May 06, 2016 at 05:07 PM 0
Share

Thank you so much for the help, i've been following the directions, you say "Drag your player's inventory into this slot" But where is the slot you speak of? Do I drag the script into that script somehow or should there be a slot in the script settings when I look at it in Unity. Thanks again. Also I seem to be getting errors, on lines "3,19" "7,13" "10,6." All of them are an "A namespace can only contain types and namespace declarations" Error.

avatar image tanoshimi · May 06, 2016 at 05:31 PM 0
Share

This is only snippets of the script - it needs to be contained in a proper C# class definition, in which case "playerInventory" becomes a slot exposed in the inspector panel onto which you can drag and drop the player inventory.

avatar image
0

Answer by normand · Apr 30, 2016 at 08:21 AM

weel you have allready your function if(numStones >=60){ Debug.Log("Do My Animation can play") }

But your probleme look like if you know how play the annimation. I suggest you yo put a ''''''''Debug.Log("Do My Animation can play")'''''''''''()

So, what i doe its .... Animator _animotor; bool canAnimate; void Start(){ animator = GetComponent(); } void Update(){ _animator.SetBool("CanPlay", canAnimate);

} and put your line code inside your trigger function if(numStones >=60){ Debug.Log("Do My Animation can play") canAnimate=true; }

adn make sure that your Paramater bool name in your animatorController is the same name as CanPlay in your script. and dont use the old Lagacy animation. So, set your model as Generic.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Le-Pampelmuse · May 06, 2016 at 08:19 PM 0
Share

Please format your code. This is horrible to read. ;)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Need help with bone animation and trigger code. 0 Answers

How do I stop my main menu from closing before the player is done interacting with it? 0 Answers

How to make an animated object inside inventory. 0 Answers

anima2d SpriteMesh Editor doesn't load meshes 3 Answers

Interpolation between key frames 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges