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 /
This question was closed Nov 12, 2015 at 05:54 AM by StrCrz for the following reason:

Went a different route completely. Thanks

avatar image
0
Question by StrCrz · Nov 10, 2015 at 07:30 AM · c#scripting problem

Time.deltatime fail and how can i apply my public GameObject other;

Hi All,

I am trying to apply a smooth door open via switch (multiple doors at once with the one switch). First problem is the swing. i have to click the door repeatedly to get it all the way. Second problem i can seem to find a way to attach the, public GameObject other;, properly so i can use the script for multiple doors/switches with out editing. Here's what i have

 public class DoorRotate : MonoBehaviour
 {
     private float smooth = 2f;
     bool dooropen = true;
     private float open = -90f;
     private float closed = 0f;
     public GameObject other;
 
     void OnMouseDown()
     {
         if (dooropen == false)
         {
             transform.Rotate(new Vector3(0, open, 0) * Time.deltaTime * smooth);
         }
         else if (dooropen == true)
         {
             transform.Rotate(new Vector3(0, closed, 0) * Time.deltaTime * smooth);
         }
     }
 }
 

Any Help is greatly appreciated

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 StrCrz · Nov 10, 2015 at 04:27 PM 0
Share

Help Please!

1 Reply

  • Sort: 
avatar image
0

Answer by Jessespike · Nov 10, 2015 at 09:25 PM

You need to update the rotation per frame. Something like this:

 float toRotation;

 void OnMouseDown()
 {
     if (dooropen)
     {
         dooropen = false;
         toRotation = closed;
     }
     else
     {
         dooropen = true;
         toRotation = open;
     }
 }

 void Update()
 {
     transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0f, toRotation, 0f), Time.deltaTime);
 }


For 2nd problem, if you want to open/close other doors. Try a public function:

  public void SwingDoor() {
       OnMouseDown();
  }

  other.GetComponent<DoorRotate>().SwingDoor();
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

Follow this Question

Answers Answers and Comments

34 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

Related Questions

how do i make the player walk the direction the camera looks at 1 Answer

Input.GetAxisRaw always returns -0.6 1 Answer

SmoothDamp bug? 0 Answers

[SOLVED] Player prefab not spawning 2 Answers

Unity Freezes After SceneManager.LoadSceneAsync 2 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