• 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 zoeroseart · Feb 17, 2019 at 01:49 AM · triggerdoorevent triggeringdoorsitem pickup

HubDoor in 2D Game kit- Trying to make a door open after collecting 3 items

I am currently going through the 2D Game Kit tutorial and package, and I am trying to create a door on my level that opens after collecting 3 keys (items). I have tried following the HubDoor guide:

https://unity3d.com/learn/tutorials/projects/2d-game-kit/hubdoor?playlist=49633

I have followed the instructions on my own door, and have connected the three keys. I was wondering what I am missing to get the event of the door opening to trigger once I do collect them, when I walk up to it. This is my current script. The door sprites will not change when I pick up a key either.

alt text I am just starting out on Unity and this would help me out a lot, thank you!

screen-shot-2019-02-16-at-54527-pm.png (87.3 kB)
Comment
Add comment · Show 10
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 zereda-games · Feb 17, 2019 at 06:48 AM 0
Share

looks like the $$anonymous$$ey Director Trigger is missing in the inspector, drag it onto the spot that says None. does your animator control that? i need more details like actual code not a visual ref of the inspector. that doesn't tell me much.

avatar image zereda-games zereda-games · Feb 17, 2019 at 07:13 AM 0
Share

hmm trying to understand what happening here lol. umm what code is controlling the players help keys? the ones picked up the Door Hub should have a static Instance Refrence to access so when the player has collected all the right keys the Instance can change a bool to true that use to be false when the player Didn't have all the keys. When that bool is true in the update $$anonymous$$ethod you need to have the animator play. so your button could be as simple as

 public static class $$anonymous$$eys{
    public static $$anonymous$$ey key1=new $$anonymous$$ey("Door 1 $$anonymous$$ey #1",0);
    public static $$anonymous$$ey key2=new $$anonymous$$ey("Door 1 $$anonymous$$ey #2",1);
    public static $$anonymous$$ey key3=new $$anonymous$$ey("Door 1 $$anonymous$$ey #3",2);
 }

 public class $$anonymous$$ey {
  public int ID;
  public string Name;

  public $$anonymous$$ey(){
      ID=0;
      Name="";
  }

  public $$anonymous$$ey(int id){
      ID=id;
      Name="";
  }

  public $$anonymous$$ey(string name, int id){
      ID=id;
      Name=name;
  }

   public string GetID(){
       return ID;
   }

   public string GetName(){
        return Name;
    }
 }

 public class $$anonymous$$y$$anonymous$$eysConroller:$$anonymous$$onoBehaviour{
     List<$$anonymous$$ey> keys=new List<$$anonymous$$ey> ();
     public bool key1Found, key2Found, key3Found;
     static Animator anim;

     void Awake(){
          keys=new List<$$anonymous$$ey> ();
     }
     void Update(){
          if(key1Found){
               keys.Add($$anonymous$$eys.$$anonymous$$ey1);
          }
          if(key2Found){
               keys.Add($$anonymous$$eys.$$anonymous$$ey2);
          }
          if(key3Found){
               keys.Add($$anonymous$$eys.$$anonymous$$ey3);
          }
     }

     public void UnlockDoor1(){

       if(Equals(keys.Contains($$anonymous$$eys.$$anonymous$$ey1)&&keys.Contains($$anonymous$$eys.$$anonymous$$ey2)&&keys.Contains($$anonymous$$eys.$$anonymous$$ey3))){
              anim=GameObject.FindObjectWithTag("Door1").GetComponent<Animator >();
              HubDoor.Instance.isDoorUnlockable=true;
              OpenDoor(anim);
              Debug.Log("Player opened Door 1");
        } else {
              HubDoor.Instance.isDoorUnlockable=false;
              Debug.Log("Player doesn't have all the keys to open door. The door remains locked.");
        }
     }

     void OpenDoor(Animator anim){
          anim.Play("Open Door");
     }
 }



Of Course you may start getting into a lot of keys and assign your bool's into a list also would help. Then you would need a forloop or a foreach loop to make the bools and the keys element ID's match with an int variable.

avatar image zoeroseart zereda-games · Feb 20, 2019 at 12:05 AM 0
Share

Hi, Thank you so much for replying, bear with me, I'm very new to all of this and chose non coding project to start with. Here is a picture of the HubDoor script: alt text

I could not find a key director trigger in the project at all, which was very confusing because I didn't know what to drag over. The code you provided looks like it would solve it, but where would I place it in my project in $$anonymous$$onodevelop? thank you again!

screen-shot-2019-02-19-at-40203-pm.jpg (441.6 kB)
avatar image zereda-games zoeroseart · Feb 20, 2019 at 03:42 AM 0
Share

do you actually understand whats goin on in my basic example? and where did this code come from as you don't know much about it so clearly it isn't yours... if i knew where it came from maybe i could be of more assistance, my code is ok.. but i wouldn't call it perfect or good. it's a just a basic concept. Also yes it would be dirived for $$anonymous$$onoBehaviour.

also

  public void OpenDoor(Animator anim){
       anim.Play("Open Door");
  }

you may wantthis /\ public to use as a button. I was just learning about event calls and that would work better in my script then how it is I$$anonymous$$O. that being said there and many ways to do things it is which was works best for you sorta thing.

Show more comments
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by HoplightUnity · Mar 11, 2019 at 11:00 AM

Hi zoeroseart,

Have you tried applying this component onto the hub door sprite itself(HubDoor0.sprite). it won't work on it's parent that holds the animator.

It is looking for the component Sprite Renderer applied on the sprite:)

Hope this helps!

Comment
Add comment · 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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

187 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I not set a trigger to happen? 1 Answer

How to get "on trigger enter"( or exit) to only react to a specific tag 1 Answer

Opening/Closing doors 1 Answer

Playing a multistage door animation with triggers. 0 Answers

Using Multiple Activated Triggers to trigger a Separate Event. 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges