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 Yuchemey · Mar 06, 2016 at 10:59 AM · c#animationscript.doordoors

Trying to make a door. Zoning or Load Level with Animation.

Hi i have been trying to make a door. That like skyrim. Opens then let's you zone into an house or castle or whatever.

I have been following like 3 tutorial at once but to no avail. here's what i have so far.

Interact

using UnityEngine; using System.Collections;

public class InteractScript : MonoBehaviour {

 public float interactDistance = 5f;

 void Update () 
 {
 if(Input.GetKeyDown(KeyCode.F))
     {
         Ray ray = new Ray(transform.position, transform.forward);
         RaycastHit hit;
         if(Physics.Raycast(ray, out hit, interactDistance))
             {
                 if(hit.collider.CompareTag("Door"))
                 {
                 hit.collider.transform.parent.GetComponent<DoorZoneScript>() .ChangeDoorState();
                 }
                 else if(hit.collider.CompareTag("NextLevelDoor"))
             {
                 hit.collider.transform.parent.GetComponent<DoorZoneScript>() .ChangeDoorState();
                 Application.LoadLevel(0);
             }
         
     }
 }

}

DoorScript

using UnityEngine; using System.Collections;

public class DoorZoneScript : MonoBehaviour {

 public bool open = false;
 public float doorOpenAngle = -15f;
 public float DoorCloseAngle= 0f;
 public float smooth = 2f;
 public AudioClip open_door;

 private AudioSource source;
 private float volLowRange = .5f;
 private float volHighRange = 1.0f;


 void Awake () 
 {
     source = GetComponent<AudioSource> ();
 }
 

 public void ChangeDoorState()
 {
     open = !open;
     if (open) 
     {
         float vol = Random.Range (volLowRange, volHighRange);
         source.PlayOneShot(open_door,vol);
     }
 }


 void Update () 
 {
     if (open)  //open = true
     {
         Quaternion targetRotation = Quaternion.Euler (0,doorOpenAngle, 0);
         transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotation, smooth * Time.deltaTime);
     }
     else
     {
         Quaternion targetRotation2 = Quaternion.Euler (0,DoorCloseAngle, 0);
         transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotation2, smooth * Time.deltaTime);
     }
 }

}

Let me know if theres a way i can do.

Comment
Add comment · Show 1
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 Yuchemey · Mar 09, 2016 at 01:49 AM 0
Share

Do i need to make the door script, Interact script, then make a trigger script for when the door opens?

I.E: Door is closed Approaches door Press F to enter Door Opens about 15f Zone in.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Yuchemey · Mar 06, 2016 at 11:00 AM

Keep in mind i am still very new at this.

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 Yuchemey · May 17, 2017 at 03:42 PM 0
Share

I found a way to make the door zone like in skyrim. - $$anonymous$$ake a script of a door to make it rotate like 15~20 degrees - Create an object and make it a trigger, place it behind the door but make sure it is Behind the door so that when it opens it triggers the zoning. with OnTriggerEnter ()

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

152 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

Related Questions

Moving an Object to a random position 3 Answers

Animations not playing correctly for FPS enemy AI 0 Answers

How to Set State/StateMechine' postion in Controller by script 0 Answers

Take damage only when attack animation is done? 1 Answer

Animations not playing correctly for FPS enemy AI 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