• 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 unity_jeQaoDwWpy4zaQ · May 29 at 07:30 AM · unity 2d2d animation

I need help with Door animations

Hi I'm creating my first game and I've been learning A LOT with this project but i'm stuck now. I was doing a key and door system that I found from Codemonkey. and it all worked untill i decided to change the colors. since i changed the colors now the 3 doors wont share the same animation. the problem is that i cant figure out how to code:


"if the green door is opened, play the 'GreenDoorOpen' animation;"


"if the blue door is opened, play the 'BlueDoorOpen' animation;"


"if the red door is opened, play the 'RedDoorOpen' animation; "


The Door Script:

 public class KeyDoor : MonoBehaviour
 {
     public Animator anim;
 
     [SerializeField] private Key.KeyType keyType;
     public Key.KeyType GetKeyType()
     {   
         return keyType;
     }
 
     public void OpenDoor()
     {
         anim.Play("DoorOpen");
     }



The KeyHolder Script:

 public class KeyHolder : MonoBehaviour
 {
     private List<Key.KeyType> keyList;
 
     private void Awake()
     {
         keyList = new List<Key.KeyType>();
     }
 
     public void Addkey(Key.KeyType keyType)
     {
         Debug.Log("Added Key: " + keyType);
         keyList.Add(keyType);
     }
 
     public void Removekey(Key.KeyType keyType)
     {
         keyList.Remove(keyType);
     }
 
     public bool Containskey(Key.KeyType keyType)
     {
        return keyList.Contains(keyType);
     }
 
 
     private void OnTriggerEnter2D(Collider2D collider)
     {
        Key key = collider.GetComponent<Key>();
        if (key != null)
        {
            Addkey(key.GetKeyType());
            Destroy(key.gameObject);
        } 
        KeyDoor keyDoor = collider.GetComponent<KeyDoor>();
        if (keyDoor != null)
        {
            if (Containskey(keyDoor.GetKeyType()))
            {
                //Currently holding Key to open this door
                Removekey(keyDoor.GetKeyType());
                keyDoor.OpenDoor();
                
            }
        } 
 
     }
 }



The key script:

 public class Key : MonoBehaviour
 {
     [SerializeField] private KeyType keyType;
 
    public enum KeyType
    {
        Red,
        Green,
        Blue
    }
 
    public KeyType GetKeyType()
    {
        return keyType;
    }
 }
Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

201 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 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 to make this shop animation and unlock system? 0 Answers

Why does my character animation freeze the first time it load each frame of the animation for the first time ?,Why does my character freeze while playing his animation for first time ? 0 Answers

Unity 2D Character gets stuck in collider 0 Answers

Block Raycast of collider when Button is hit 0 Answers

Referencing a script of a parent of a instantiated instance from another instantiated instance 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