Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 soco2211 · Mar 15, 2017 at 05:48 PM · gameobjectbeginnernot working

Making a specific door open in a dungeon with multiple doors

I've searched several different questions and can't seem to figure out my problem. I'm trying to open a specific door in a dungeon that currently has 2 doors(there will be more doors if I ever figure this out). In my PlayerController script I declared

 public DoorOpen doorOpen; //reference to my DoorOpen Class
 [SerializeField]private GameObject currentDoor; //reference to the door I'm trying to currently open

My open door script is:

  //Door check
                 RaycastHit doorHit;
                 //GameObject currentDoor;
                 Debug.DrawRay (transform.position + new Vector3(0f, 1f,0f), transform.forward * 2f, Color.red);
                 if(Physics.Raycast(transform.position + new Vector3(0f, 1f,0f), transform.forward * 2f, out doorHit)){
                     if(doorHit.collider.gameObject.tag == "Door" && Input.GetKeyDown(KeyCode.R)){
                         print ("Open the door!");
                         currentDoor = doorHit.collider.gameObject; //assigns the current door
                         doorOpen.OpenCheck (); //runs script attached to DoorOpen class
                     }
                 }

My DoorOpen class:

public class DoorOpen : MonoBehaviour { public bool isDoorOpen = false;

 public void OpenCheck(){
     if(isDoorOpen == false){
         isDoorOpen = true;
         print ("Opened");
         Vector3 to = new Vector3(0,90,0);
         transform.eulerAngles = Vector3.Lerp (transform.rotation.eulerAngles, to, Time.deltaTime * 90);
     }else{
         isDoorOpen = false;
         print ("Closed");
         Vector3 back = new Vector3 (0, -90, 0);
         transform.eulerAngles = Vector3.Lerp (-transform.rotation.eulerAngles, back, Time.deltaTime * 90);
     }
 }

}

What I'm currently getting is that in my Player Inspector window, CurrentDoor is assigning the proper door, but Door Open is remaining null. I'm thinking if I can assigned CurrentDoor to DoorOpen it should work, but when I try to do that it get "Assets/Scripts/Player/PlayerController.cs(50,17): error CS0029: Cannot implicitly convert type UnityEngine.GameObject' to DoorOpen'" If I take out the CurrentDoor step and just assign the GameObject 'door' in the player Inspector window, it will only open that specific door and not any other door.

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

1 Reply

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

Answer by Commoble · Mar 15, 2017 at 06:10 PM

If you have a reference to the gameobject with the DoorOpen component on it, you can get a reference to the DoorOpen script with GetComponent. So then you can do:

 doorObject = doorHit.collider.gameObject;
 DoorOpen doorScript = doorObject.GetComponent<DoorOpen>();
 if (doorScript != null)
 {
     doorScript.OpenCheck();
 }
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 soco2211 · Mar 15, 2017 at 07:04 PM 0
Share

That worked perfectly. Thanks so much, I felt like I was pretty close just couldn't get the last bit figured out.

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

116 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

Related Questions

Learning to equip weapons etc to character but its not working! 1 Answer

Problem with game animation for gameobject movement 0 Answers

Activating a gameobject from a script attached to a different gameobject. 1 Answer

Sprite Rendering Order 1 Answer

How do i convert game object counts, into int, and put into string? 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